編輯:Android開發實例
代碼示例:
package com.study.ws;
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class WSClient extends Activity {
private Button search;
private EditText phone;
private TextView result;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
search=(Button)findViewById(R.id.search);
phone=(EditText)findViewById(R.id.phone);
result=(TextView)findViewById(R.id.result);
search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String strPhone=phone.getText().toString().trim();
if(!(strPhone.length()==0||strPhone.equals("")))
{
String str = "";
try {
str = getPhoneInfo(strPhone);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
result.setText(str);
}
}
});
}
public String getPhoneInfo(String phoneName) throws IOException, XmlPullParserException
{
//返回的查詢結果
String result = null;
//調用webservice接口的名稱空間
String nameSpace="http://WebXml.com.cn/";
//調用的方法名
String methodName="getMobileCodeInfo";
//將方法名和名稱空間綁定在一起
String SOAP_ACTION = nameSpace + methodName;
//獲得返回請求對象
SoapObject request = new SoapObject(nameSpace, methodName);
//設置需要返回請求對象的參數
request.addProperty("mobileCode", phoneName);
request.addProperty("userId", "");
//設置soap的版本
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
//設置是否調用的是dotNet開發的
envelope.dotNet = true;
//
envelope.bodyOut = request;
AndroidHttpTransport hts = new AndroidHttpTransport
("http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx");
// web service請求
hts.call(SOAP_ACTION, envelope);
// 得到返回結果
Object o = envelope.getResponse();
result = o.toString();
return result;
}
}
可以顯示在的Android任務,通過加載進度條的進展。進度條有兩種形狀。加載欄和加載微調(spinner)。在本章中,我們將討論微調(spinner)。Spinner 用
JSON代表JavaScript對象符號。它是一個獨立的數據交換格式,是XML的最佳替代品。本章介紹了如何解析JSON文件,並從中提取所需的信息。Android提供了四個
打開packages\apps\PackageInstaller下的清單文件XML/HTML代碼
可以顯示在的Android任務,通過加載進度條的進展。進度條有兩種形狀。加載欄和加載微調(spinner)。在本章中,我們將討論微調(spinner)。Spinner 用