安卓的基础知识学了一个多月后一直觉得遇到了瓶颈,想写几个APP来证明一下自己,不过后面还是发现自己太年轻了,毕竟技术的路还是很长的,看到这篇博客的朋友希望能从中学到一些东西,这样这篇博客就没有白费。
除了号码归属地,苹果序列号,身份证号码查询,邮编,快递查询都可以借鉴。不过有些API申请是需要费用的。但是刚开始申请会免费赠送你几次查询。
工具:
Android studio
建议使用Android studio
准备工作:
去聚合数据申请一个号码归属地查询的API,网址:https://www.juhe.cn/(申请过程百度上都有)

具体实现:
这是个典型的客户端请求服务器数据,服务器返回json数据给客户端,然后再经由客户端对json格式的数据进行解析的例子。
JSON返回示例:
{
"resultcode":"200",
"reason":"Return Successd!",
"result":{
"province":"浙江",
"city":"杭州",
"areacode":"0571",
"zip":"310000",
"company":"中国移动",
"card":"移动动感地带卡"
}
}
这个json比较简单,直接用JSONobject进行解析获取数据即可。
界面代码如下:
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.administrator.num_find.MainActivity">
<EditText
android:layout_marginTop="20dp"
android:id="@+id/editText"
android:text="请输入号码"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button