本文主要是介绍webservice _ 号码归属地查询,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
参考网址: webservice.webxml.com.cn
---------------------------------------------------------------------------
号码归属地查询:
public class MainActivity extends Activity implements OnClickListener {
private EditText et ;
private Button bt ;
private TextView tv ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout. activity_main );
et =(EditText) findViewById(R.id. et );
bt =(Button) findViewById(R.id. bt );
tv =(TextView) findViewById(R.id. iv );
//注册按钮监听器
bt .setOnClickListener( this );
}
/**
* 按钮触发事件
*/
@Override
public void onClick(View v) {
String number= et .getText().toString().trim(); //获取号码
String path= "http://webservice.webxml.com.cn//WebServices/MobileCodeWS.asmx/getMobileCodeInfo" ;
//创建AsyncHttpClient对象
AsyncHttpClient client= new AsyncHttpClient();
RequestParams params= new RequestParams();
params.put( "mobileCode" , number);
params.put( "userID" , "" );
//获取网络xml文件
client.get(path , params, new AsyncHttpResponseHandler(){
@Override
public void onSuccess(String content) {
try {
//创建pull解析器
XmlPullParser parser = Xml.newPullParser();
parser.setInput( new StringReader(content)); //解析 xml字节流
for ( int type=parser.getEventType();type!=XmlPullParser. END_DOCUMENT ;type=parser.next()){
if (type == XmlPullParser. START_TAG && "string" .equals(parser.getName())){
tv .setText(parser.nextText());
}
}
} catch (Exception e) {
e.printStackTrace();
System. out .println( "请求失败..." );
}
}
});
}
}
这篇关于webservice _ 号码归属地查询的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!