手机号码归属地查询
MobileAddressQuery
Android通过调用Webservice实现手机号码归属地查询
注:http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx是本文webservice的提供商
具体的用法见:
http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?op=getMobileCodeInfo
android.os.NetworkOnMainThreadException
一个APP如果在主线程中请求网络操作,将会抛出此异常。Android这个设计是为了防止网络请求时间过长而导致界面假死的情况发生。
解决方案有两个,一个是使用StrictMode,二是使用线程来操作网络请求。
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">手机号码归属地查询</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="mobile">手机号码</string>
<string name="button">归属地查询</string>
<string name="error">查询失败</string>
</resources>
fragment_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="co