Preface
A long time ago, I saw the source code of a mobile phone security guard and mobile assistant on the Internet. I haven't looked at some implementations in it. Today, I downloaded it and ran it, it is found that mobile guard is not actually a public feeling of text message on the page. It needs to be analyzed in detail. This article will analyze the mobile assistant Reid's number for local query.
Source code Portal:
Git clone git@github.com: avenwu/mobilehelper. Git or
Git clone https://github.com/avenwu/mobilehelper.git
The technologies used in this article are as follows:
- JSON Parsing
- Android volley, https://android.googlesource.com/platform/frameworks/volley
- Roboguice, https://github.com/roboguice/roboguice
Body
I think there are two ways to check the location: one is to query the local database, which requires you to have data on the mobile phone numbers of major carriers, and the other is to query the network, there are many websites on the Internet that provide number queries, but many additional data will be returned.ArticleThe content is basically the same. I don't know if the article is original:
Http://blog.sina.com.cn/s/blog_7bac4707010143o2.html
Http://www.cnblogs.com/88223100/archive/2013/03/06/2945474.html
The above list is actually some good clean APIs. The returned data is concise and clear, mainly in XML and JSON formats,
Choose https://www.baifubao.com/callback now? Cmd = 1059 & callback = phone & phone = 13717830629 as the query API,
The returned results are as follows:
Phone ({meta: {Result: "0", result_info: "", jump_url: ""}, data: {OPERATOR: "mobile", Area: "Jiangsu", area_operator: "Jiangsu mobile "}})
This is in JSON format, but it is not completely correct. Therefore, make some modifications during parsing.
The correct JSON data format is:
(1) An object starts with "{" (left parenthesis) and ends with "}" (right Parenthesis.
(2) Each "name" is followed by a ":" (colon );
(3) Use commas (,) to separate 'name/value' pairs.
When sending a request, you only need to replace the parameter with the phone number to be queried:
String url = pre_url.replace ("phonenumber" , Editphonenumber. gettext (). tostring (). Trim (); phonerequest = New Stringrequest (URL, New Listener <string> () {@ Override Public Void Onresponse (string arg0 ){ /* * Phone ({meta: {Result: "0", result_info: "", * jump_url: ""}, data: {OPERATOR: "mobile", Area: "Jiangsu ", * area_operator: "Jiangsu mobile "}}) */ Int Start = arg0.indexof ("{" ); Int End = arg0.lastindexof ("}") + 1 ; Jsonobject JSON = Null ; Try {JSON = New Jsonobject (arg0.substring (START, end); stringbuffer result = New Stringbuffer (); Result. append ( "Mobile Phone number:" +Editphonenumber. gettext (). tostring (). Trim (); Result. append ( "\ N OPERATOR:" + JSON. getjsonobject ("data" ). Get ( "Area_operator" ); Tvresult. settext (result. tostring ());} Catch (Jsonexception e) {e. printstacktrace ();}}}, New Errorlistener () {@ override Public Void Onerrorresponse (volleyerror arg0) {toast. maketext (mainactivity. This , R. String. query_failed, Toast. length_short). Show () ;}); netmanager. queryphonenumber (phonerequest );