Below I from the perspective of Android development, simply write how to get mobile device information and mobile phone number
Preparation conditions: An Android phone, mobile SIM card to ensure plug-in phone, Eclipse ADT and ANDROID-SDK development environment
First step: Create a new Android project (Jinshantest),
and need to add permissions in the project's Androidmanifest.xml file
<uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>
Legend:
Step Two: Create a new tool class Phoneinfo.java
[Java]View Plaincopy
- Package com.jinshan.test;
- Import Android.content.Context;
- Import Android.telephony.TelephonyManager;
- /**
- * Read the phone device information test code
- * Http://www.souapp.com Search Application Network
- * [Email protected]
- * Song Lipo
- */
- Public class Phoneinfo {
- private Telephonymanager Telephonymanager;
- /**
- * International Mobile Subscriber Identification code
- */
- private String IMSI;
- private Context cxt;
- Public Phoneinfo (context context) {
- Cxt=context;
- Telephonymanager = (Telephonymanager) context
- . Getsystemservice (Context.telephony_service);
- }
- /**
- * Get Phone number
- */
- Public String Getnativephonenumber () {
- String nativephonenumber=null;
- Nativephonenumber=telephonymanager.getline1number ();
- return nativephonenumber;
- }
- /**
- * Access to mobile service provider information
- */
- Public String Getprovidersname () {
- String providersname = "n/a";
- try{
- IMSI = Telephonymanager.getsubscriberid ();
- //IMSI front 3 bit 460 is the country, followed by 2 bit 00 02 is China Mobile, 01 is China Unicom, 03 is Chinese telecom.
- System.out.println (IMSI);
- if (Imsi.startswith ("46000") | | Imsi.startswith ("46002")) {
- Providersname = "China Mobile";
- } Else if (Imsi.startswith ("46001")) {
- Providersname = "China Unicom";
- } Else if (Imsi.startswith ("46003")) {
- Providersname = "China Telecom";
- }
- }catch (Exception e) {
- E.printstacktrace ();
- }
- return providersname;
- }
- Public String Getphoneinfo () {
- Telephonymanager TM = (Telephonymanager) cxt.getsystemservice (Context.telephony_service);
- StringBuilder sb = new StringBuilder ();
- Sb.append ("\ndeviceid (IMEI) =" + Tm.getdeviceid ());
- Sb.append ("\ndevicesoftwareversion =" + tm.getdevicesoftwareversion ());
- Sb.append ("\nline1number =" + Tm.getline1number ());
- Sb.append ("\nnetworkcountryiso =" + Tm.getnetworkcountryiso ());
- Sb.append ("\nnetworkoperator =" + Tm.getnetworkoperator ());
- Sb.append ("\nnetworkoperatorname =" + Tm.getnetworkoperatorname ());
- Sb.append ("\nnetworktype =" + Tm.getnetworktype ());
- Sb.append ("\nphonetype =" + Tm.getphonetype ());
- Sb.append ("\nsimcountryiso =" + Tm.getsimcountryiso ());
- Sb.append ("\nsimoperator =" + Tm.getsimoperator ());
- Sb.append ("\nsimoperatorname =" + Tm.getsimoperatorname ());
- Sb.append ("\nsimserialnumber =" + Tm.getsimserialnumber ());
- Sb.append ("\nsimstate =" + tm.getsimstate ());
- Sb.append ("\nsubscriberid (IMSI) =" + Tm.getsubscriberid ());
- Sb.append ("\nvoicemailnumber =" + Tm.getvoicemailnumber ());
- return sb.tostring ();
- }
- }
Step three: Add the calling code in the activity,jinshantestactivity that starts:
[Java]View Plaincopy
- Package com.jinshan.test;
- Import android.app.Activity;
- Import Android.os.Bundle;
- Public class Jinshantestactivity extends Activity {
- /** Called when the activity is first created. * /
- @Override
- public void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- Setcontentview (R.layout.main);
- Phoneinfo siminfo = new Phoneinfo (jinshantestactivity. this);
- System.out.println ("Getprovidersname:" +siminfo.getprovidersname ());
- System.out.println ("Getnativephonenumber:" +siminfo.getnativephonenumber ());
- System.out.println ("------------------------");
- System.out.println ("Getphoneinfo:" +siminfo.getphoneinfo ());
- }
- }
Fourth step, connect your phone to your computer using a USB cable, and make sure it's connected and start working on the project
Finally, we look at the Logcat log and the results are as follows:
------------------------------------------------------------
04-01 16:20:57.105:i/system.out (952): 460003121934674
04-01 16:20:57.105:i/system.out (952): Getprovidersname: China Mobile
04-01 16:20:57.115:i/system.out (952): getnativephonenumber:136xxxxxxx
04-01 16:20:57.115:i/system.out (952):------------------------
04-01 16:20:57.145:i/system.out (952): Getphoneinfo:
04-01 16:20:57.145:i/system.out (952): DeviceId (IMEI) = 352xxxxxxxx61328
04-01 16:20:57.145:i/system.out (952): Devicesoftwareversion = 01
04-01 16:20:57.145:i/system.out (952): Line1number = 136XXXXXXX
04-01 16:20:57.145:i/system.out (952): Networkcountryiso = cn
04-01 16:20:57.145:i/system.out (952): Networkoperator = 46000
04-01 16:20:57.145:i/system.out (952): Networkoperatorname = China Mobile
04-01 16:20:57.145:i/system.out (952): Networktype = 2
04-01 16:20:57.145:i/system.out (952): Phonetype = 1
04-01 16:20:57.145:i/system.out (952): Simcountryiso = cn
04-01 16:20:57.145:i/system.out (952): Simoperator = 46000
04-01 16:20:57.145:i/system.out (952): Simoperatorname = CMCC
04-01 16:20:57.145:i/system.out (952): Simserialnumber = 898xxxxxx90108
04-01 16:20:57.145:i/system.out (952): Simstate = 5
04-01 16:20:57.145:i/system.out (952): SubscriberId (IMSI) = 46000xxxxxxxx4674
So let's explain what the above information means.
Getnativephonenumber Get the phone number
DeviceId (IMEI) Mobile International Mobile Subscriber ID
Networkoperator Mobile operator number
Networkoperatorname Mobile operator Name
Simserialnumber simoperator simcountryiso simserialnumber SubscriberId (IMSI) Some details about mobile SIM card
In fact, the code does not write to get system.android_id this operation, because many mobile devices do not get andnroid_id
Of course, today we mainly talk about <uses-permission android:name= "Android.permission.READ_PHONE_STATE"/> Light Use this permission we can get mobile device information and mobile phone number
If you want to get WiFi, Bluetooth, GPS, read-write sdcard more information, you need to add additional permissions.
In addition, this test I take my phone SIM card test is able to get to the mobile phone number, of course, some mobile phone number is not available, here also gives you a list of reasons,
Mobile phone numbers are not available for all. Just a part of it can get.
This is due to the fact that the mobile operator does not write data from the mobile phone number to the SIM card. The SIM card only has the unique number, for the network and the device recognition that is the IMSI number, the cell phone signal also can say is passes through this number in the network, is not the mobile phone number. Just imagine, after your SIM is lost, do you have a new one that will change the number? No, it is because the IMSI number that corresponds to your mobile phone number is modified in the mobile operator to the IMSI number of the new SIM card.
So why does the phone number have to show it?
This is like a variable, and when the mobile operator assigns it a value, it will naturally have a value. No value is naturally empty.
For mobile users, the mobile number (MDN) is saved in the operator's server instead of being stored in the SIM card. The SIM card retains only IMSI and some verification information. Every time the mobile network registration, will be in the form of text messages to the IMSI and authentication information to the operator's server, the server after the completion of the registration action, will be in the form of text messages will be issued to the mobile phone. The content will be different depending on the conditions.
If the server in the issued text message, does not include the phone number, the phone is unable to obtain the phone number. If the text contains a number, the phone will cache it for his use. In addition, for other operators ' SIM cards or Uim cards, the MDN may be saved in the UIM card. 100% being able to get a native number is unlikely.
Mobile Shenzhou Line, Unicom's card can be taken. The dynamic zone is not available. Other cards have not been tried yet.
The ability to read the SIM card number should have a precondition. That is, the SIM card has been written to the local number, otherwise it cannot be read.
Sample code for Android app to get mobile device information and mobile phone number