首页 > 其他分享 >手把手叫你用android 调研web services

手把手叫你用android 调研web services

时间:2023-07-27 19:31:35浏览次数:44  
标签:web Eclipse project Android services new android your


Step by Step Method to Access Webservice from Android


By Mihira Prasanna | 24 Sep 2010


Java Mobile Android


How to access webservice from Android mobile application


 



Part of The Mobile Zone



See Also







21


Sponsored Links



System Requirements

The sections below describe the system and software requirements for developing Android applications using the Android

Supported Operating Systems

  • Windows XP (32-bit) or Vista (32- or 64-bit)
  • Mac OS X 10.5.8 or later (x86 only)
  • Linux (tested on Linux Ubuntu Hardy Heron)

Supported Development Environments

Eclipse IDE

  • Eclipse 3.4 (Ganymede) or 3.5 (Galileo)

Caution: There are known issues with the ADT plugin running with Eclipse 3.6. Please stay on 3.5 until further notice.

  • Eclipse JDT plugin (included in most Eclipse IDE packages)
  • If you need to install or update Eclipse, you can download it from http://www.eclipse.org/downloads/ . Several types of Eclipse packages are available for each platform. For developing Android
  • Eclipse IDE for Java EE Developers
  • Eclipse IDE for Java Developers
  • Eclipse for RCP/Plug-in Developers
  • Eclipse Classic (versions 3.5.1 and higher)
  • JDK 5 or JDK 6 (JRE alone is not sufficient)
  • Android (optional)
  • Not compatible with Gnu Compiler for Java (gcj)

Hardware Requirements

The Android

Component type

Approximate size

Comments

SDK Tools

50 MB

Required.

Android

150 MB

At least one platform is required.

SDK Add-on (each)

100 MB

Optional.

USB Driver for Windows

10 MB

Optional. For Windows only.

Samples (per platform)

10M

Optional.

Offline documentation

250 MB

Optional.

Note that the disk-space requirements above are in addition to those of the Eclipse IDE, JDK, or other prerequisite tools that you may need to install on your development computer.

Installing the ADT Plugin for Eclipse

  1. Start Eclipse, then select Help > Install New Software .
  2. In the Available Software dialog, click Add... .
  3. In the Add Site dialog that appears, enter a name for the remote site (for example, "Android

In the "Location" field, enter this URL:

https://dl-ssl.google.com/android

Note : If you have trouble acquiring the plugin, you can try using "http" in the URL, instead of "https" (https is preferred for security reasons).

Click OK .

  1. Back in the Available Software view, you should now see "Developer Tools" added to the list. Select the checkbox next to Developer Tools, which will automatically select the nested tools Android DDMS and Android Development Tools. Click Next .
  2. In the resulting Install Details dialog, the Android DDMS and Android Development Tools features are listed. Click Next to read and accept the license agreement and install any dependencies, then click Finish .
  3. Restart Eclipse.

Configuring the ADT Plugin

Once you've successfully downloaded ADT as described above, the next step is to modify your ADT preferences in Eclipse to point to the Android

  1. Select Window > Preferences... to open the Preferences panel (Mac OS X: Eclipse > Preferences ).
  2. Select Android from the left panel.
  3. For the SDK Location in the main panel, click Browse... and locate your downloaded SDK directory.

Click Apply , then OK .

Creating an Android

The ADT plugin provides a New Project Wizard that you can use to quickly create a new Android

  1. Select File > New > Project .
  2. Select Android > Android , and click Next .
  3. Select the contents for the project:
  • Enter 'Android '. This will be the name of the folder where your project is created.
  • Under Contents, select Create new project in workspace . Select your project workspace location.
  • Under Target, select an Android target to be used as the project's Build Target. The Build Target specifies which Android platform you'd like your application built against. Unless you know that you'll be using new APIs introduced in the latest SDK, you should select a target with the lowest platform version possible.
    Note: You can change your the Build Target for your project at any time: Right-click the project in the Package Explorer, select Properties , select Android and then check the desired Project Target.
  • Under Properties, fill in all necessary fields.
  • Enter an Application name as ' Android . This is the human-readable title for your application — the name that will appear on the Android
  • Enter a Package name as 'com.test.android '. This is the package namespace (following the same rules as for packages in the Java programming language) where all your source code will reside.
  • Select Create Activity (optional, of course, but common) and enter a name (give 'FirstAppUI ') for your main Activity class.
  • Enter a Min SDK Version . This is an integer that indicates the minimum API Level required to properly run your application. Entering this here automatically sets the minSdkVersion attribute in the <uses-sdk> of your Android
  1. Click Finish .

Tip: You can also start the New Project Wizard from the New icon in the toolbar.

Once you complete the New Project Wizard, ADT creates the following folders and files in your new project:


src/

Includes your stub Activity Java file. All other Java files for your application go here. <Android / (e.g., Android )


Includes the android file that your application will build against. This is determined by the build target that you have chosen in the New Project Wizard.


gen/


This contains the Java files generated by ADT, such as your R.java file and interfaces created from AIDL files.


assets/

This is empty. You can use it to store raw asset files. res/

A folder for your application resources, such as drawable files, layout files, string values, etc. Android

Android default.properties

This file contains project settings, such as the build target. This file is integral to the project, as such, it should be maintained in a Source Revision Control system. It should never be edited manually — to edit project properties, right-click the project folder and select "Properties".

Creating an AVD

An Android

To create an AVD from Eclipse:

  1. Select Window > Android , or click the Android
  2. In the Virtual Devices panel, you'll see a list of existing AVDs. Click New to create a new AVD.
  3. Fill in the details for the AVD. Give it a name, a platform target, an SD card size, and a skin (HVGA is default).
    Note: Be sure to define a target for your AVD that satisfies your application's Build Target (the AVD platform target must have an API Level equal to or greater than the API Level that your application compiles against).
  4. Click Create AVD .

Your AVD is now ready and you can either close the SDK and AVD Manager, create more AVDs, or launch an emulator with the AVD by selecting a device and clicking Start .

Code your FirstAppUI.java class like below:


手把手叫你用android 调研web services_android Collapse | Copy Code


package
 com.test.android
;

import
 org.ksoap2.SoapEnvelope;
import
 org.ksoap2.serialization.SoapObject;
import
 org.ksoap2.serialization.SoapSerializationEnvelope;
import
 org.ksoap2.transport.HttpTransportSE;

import
 android
.app.Activity;
import
 android
.os.Bundle;
import
 android
.widget.ArrayAdapter;
import
 android
.widget.AutoCompleteTextView;

public
 class
 FirstAppUI extends
 Activity {

	
	private
 static
 final
 String NAMESPACE = "
com.service.ServiceImpl"
;
	private
 static
 final
 String URL = 
		"
http://192.168.202.124:9000/Android
WS/wsdl/ServiceImpl.wsdl"
;	
	private
 static
 final
 String SOAP_ACTION = "
ServiceImpl"
;
	private
 static
 final
 String METHOD_NAME = "
message"
;
	
	private
 static
 final
 String[] sampleACTV = new
 String[] {
	"
android
"
, "
iphone"
, "
blackberry"

	};

	@Override
	public
 void
 onCreate(Bundle savedInstanceState) {
		super
.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		ArrayAdapter<String> arrAdapter = new
 ArrayAdapter<String>
		(this
, android
.R.layout.simple_dropdown_item_1line, sampleACTV);

		AutoCompleteTextView ACTV = (AutoCompleteTextView)findViewById
						(R.id.AutoCompleteTextView01);
		ACTV.setAdapter(arrAdapter);

		SoapObject request = new
 SoapObject(NAMESPACE, METHOD_NAME); 		
		SoapSerializationEnvelope envelope = 
			new
 SoapSerializationEnvelope(SoapEnvelope.VER11); 

		envelope.setOutputSoapObject(request);
		HttpTransportSE android
HttpTransport = new
 HttpTransportSE(URL);

		try
 {
			android
HttpTransport.call(SOAP_ACTION, envelope);
			SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
			ACTV.setHint("
Received :"
 + resultsRequestSOAP.toString());
		} catch
 (Exception e) {
			e.printStackTrace();
		}
	}
}

Insert AutoCompleteTextView to your res>layout >main.xml as:


手把手叫你用android 调研web services_android Collapse | Copy Code


<?
xml
 version
="
1.0"
 encoding
="
utf-8"
?
>
  
<
LinearLayout
 android
:id
="
@+id/LinearLayout01"

     android
:layout_width
="
fill_parent"
     
     android
:layout_height
="
fill_parent"
     
     xmlns:android

="
http://schemas.android
.com/apk/res/android
"
>
  

     <
AutoCompleteTextView
     
         android
:id
="
@+id/AutoCompleteTextView01"
         
         android
:layout_width
="
wrap_content"
         
         android
:layout_height
="
wrap_content"
         
         android
:hint
="
This is Hint"
         
         android
:width
="
240px"
 /
>
  

 <
/
LinearLayout
>

Insert Internet access permission to your mobile application in Android file as:


手把手叫你用android 调研web services_android Collapse | Copy Code


<?
xml
 version
="
1.0"
 encoding
="
utf-8"
?
>

<
manifest
 xmlns:android

="
http://schemas.android
.com/apk/res/android
"

      package
="
com.test.android
"

      android
:versionCode
="
1"

      android
:versionName
="
1.0"
>

    <
application
 android
:icon
="
@drawable/icon"
 android
:label
="
@string/app_name"
>

        <
activity
 android
:name
="
.FirstAppUI"

                  android
:label
="
@string/app_name"
>

            <
intent-filter
>

                <
action
 android
:name
="
android
.intent.action.MAIN"
 /
>

                <
category
 android
:name
="
android
.intent.category.LAUNCHER"
 /
>

            <
/
intent-filter
>

        <
/
activity
>

    <
/
application
>

    <
uses-permission
 android
:name
="
android
.permission.INTERNET"
>
<
/
uses-permission
>

    <
uses-sdk
 android
:minSdkVersion
="
8"
 /
>


<
/
manifest
>

ServiceImpl.wsdl :


手把手叫你用android 调研web services_android Collapse | Copy Code


<?
xml
 version
="
1.0"
 encoding
="
UTF-8"
?
>

<
wsdl:definitions
 targetNamespace
=http://service.com
 
	xmlns:apachesoap
=http://xml.apache.org/xml-soap
 
	xmlns:impl
="
http://service.com"
 xmlns:intf
=http://service.com
 
	xmlns:wsdl
=http://schemas.xmlsoap.org/wsdl/
 
	xmlns:wsdlsoap
=http://schemas.xmlsoap.org/wsdl/soap/
 
	xmlns:xsd
="
http://www.w3.org/2001/XMLSchema"
>

<!--
WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
-->

 <
wsdl:types
>

  <
schema
 elementFormDefault
="
qualified"
 
      targetNamespace
="
http://service.com"
 xmlns
="
http://www.w3.org/2001/XMLSchema"
>

   <
element
 name
="
message"
>

    <
complexType
/
>

   <
/
element
>

   <
element
 name
="
messageResponse"
>

    <
complexType
>

     <
sequence
>

      <
element
 name
="
messageReturn"
 type
="
xsd:string"
/
>

     <
/
sequence
>

    <
/
complexType
>

   <
/
element
>

  <
/
schema
>

 <
/
wsdl:types
>


   <
wsdl:message
 name
="
messageResponse"
>

      <
wsdl:part
 element
="
impl:messageResponse"
 name
="
parameters"
>

      <
/
wsdl:part
>

   <
/
wsdl:message
>

   <
wsdl:message
 name
="
messageRequest"
>

      <
wsdl:part
 element
="
impl:message"
 name
="
parameters"
>

      <
/
wsdl:part
>

   <
/
wsdl:message
>

   <
wsdl:portType
 name
="
ServiceImpl"
>

      <
wsdl:operation
 name
="
message"
>

         <
wsdl:input
 message
="
impl:messageRequest"
 name
="
messageRequest"
>

       <
/
wsdl:input
>

         <
wsdl:output
 message
="
impl:messageResponse"
 name
="
messageResponse"
>

       <
/
wsdl:output
>

      <
/
wsdl:operation
>

   <
/
wsdl:portType
>

   <
wsdl:binding
 name
="
ServiceImplSoapBinding"
 type
="
impl:ServiceImpl"
>

      <
wsdlsoap:binding
 style
="
document"
 
	transport
="
http://schemas.xmlsoap.org/soap/http"
/
>

      <
wsdl:operation
 name
="
message"
>

         <
wsdlsoap:operation
 soapAction
="
"
/
>

         <
wsdl:input
 name
="
messageRequest"
>

            <
wsdlsoap:body
 use
="
literal"
/
>

         <
/
wsdl:input
>

         <
wsdl:output
 name
="
messageResponse"
>

            <
wsdlsoap:body
 use
="
literal"
/
>

         <
/
wsdl:output
>

      <
/
wsdl:operation
>

   <
/
wsdl:binding
>

   <
wsdl:service
 name
="
ServiceImplService"
>

      <
wsdl:port
 binding
="
impl:ServiceImplSoapBinding"
 name
="
ServiceImpl"
>

         <
wsdlsoap:address
 location
=
		"
http://localhost:9000/Android
WS/services
/ServiceImpl"
/
>

      <
/
wsdl:port
>

   <
/
wsdl:service
>

<
/
wsdl:definitions
>

Thanks!

History

  • 24th September, 2010: Initial post


License


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


标签:web,Eclipse,project,Android,services,new,android,your
From: https://blog.51cto.com/u_16034393/6871735

相关文章

  • CTFer成长记录——CTF之Web专题·[ACTF2020 新生赛]Include
    一、题目链接https://buuoj.cn/challenges#[ACTF2020%20新生赛]Include二、解法步骤  打开网页:    有趣的是无论是查看源代码还是bp抓包都一无所获,这题考的是php的filter伪协议进行文件包含:  php://filter:(fromhttps://blog.csdn.net/qq_42404383/article/details......
  • Android开发笔记:屏幕适配
    这几天刚刚接触了新的项目,做一个android客户端。本周的工作是完成客户端的UI界面和功能实现,但是对于Android开发最头疼的部分,即是对于纷杂的屏幕做适配的工作现在来说是最棘手的!图像显示所需的概念:像素:一幅图片的显示就是由许多显示着不同颜色的小方格组成的,这样的小方格就被称......
  • android studio输入对话框
    AndroidStudio输入对话框AndroidStudio是一款为Android应用程序开发提供支持的集成开发环境(IDE)。在开发过程中,我们经常需要与用户进行交互,而输入对话框是其中一个重要的组成部分。本文将向您介绍如何在AndroidStudio中创建和使用输入对话框,并提供相应的代码示例。创建输入对话......
  • android studio使指定页面不可显示
    AndroidStudio使指定页面不可显示在开发Android应用程序时,有时我们希望某些页面在特定条件下不可见。AndroidStudio提供了多种方法来实现这一目标,如通过布局文件、代码逻辑或使用Fragment等。本文将介绍几种常见的方法,并提供相应的代码示例。方法一:通过布局文件设置可见性在布......
  • android studio切换SDK
    如何在AndroidStudio中切换SDK作为一名经验丰富的开发者,我将向你介绍在AndroidStudio中如何切换SDK的步骤和相关代码。下面是整个流程的概览:步骤描述步骤一打开项目设置步骤二选择新的SDK版本步骤三应用更改接下来,我将详细解释每一步需要做什么,并提供相......
  • android studio期末项目
    AndroidStudio期末项目实现指南概述在这篇文章中,我将教会你如何通过AndroidStudio实现一个期末项目。我会按照以下步骤详细说明整个流程,并提供每个步骤所需的代码和注释。步骤概览步骤描述1.创建新项目在AndroidStudio中创建一个新的项目2.设计用户界面使用......
  • android studio顶部标题栏
    AndroidStudio顶部标题栏在Android开发中,AndroidStudio是一个非常常用的开发工具。它提供了许多强大的功能,其中之一就是顶部标题栏。顶部标题栏是AndroidStudio界面中的一个重要组成部分,它包含了许多有用的功能和工具。本文将介绍AndroidStudio顶部标题栏的特点、功能和如何使......
  • android studio调试手机包
    AndroidStudio调试手机包AndroidStudio是一款官方提供的用于开发Android应用程序的集成开发环境(IDE)。在开发过程中,我们经常需要将应用程序安装到手机上进行测试和调试,以确保应用程序的正常运行。本文将介绍如何使用AndroidStudio调试手机包,并提供一些代码示例。1.配置Android......
  • android studio创建avd 知乎
    在AndroidStudio中创建AVD(AndroidVirtualDevice)的步骤对于刚入行的开发者来说,创建AVD可能是一个全新的概念。AVD是一个虚拟的Android设备,用于在AndroidStudio中进行应用程序的测试和调试。下面是创建AVD的步骤:步骤描述1打开AndroidStudio2打开AVDManager3......
  • android studio 依赖重复如何解决
    解决AndroidStudio依赖重复问题当我们在使用AndroidStudio开发Android应用时,有时会遇到依赖重复的问题。这种情况通常会导致构建失败或者应用崩溃。本文将详细介绍如何解决这个实际问题,并提供示例代码作为参考。问题描述在开发过程中,我们通常会在build.gradle文件中添......