In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the code examples for android Android app to obtain mobile device information and mobile phone numbers. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Preparation conditions: an Android phone, SIM card to make sure it is plugged into the phone, eclipse ADT and android-sdk development environment
Step 1: create a new android project (JinshanTest)
And need to add permissions in the AndroidManifest.xml file of the project
Step 2: create a new tool class PhoneInfo.java
1.package com.jinshan.test; 2. 3. 4.import android.content.Context; 5.import android.telephony.TelephonyManager; 6. 7 private TelephonyManager telephonyManager 8. * read the test code for mobile device information 9. * http://www.souapp.com search App 10. * song2c@163.com 11. * Song Libo 12. * / 13.public class PhoneInfo {14. 15. Private TelephonyManager telephonyManager 16. / * 17. * International Mobile subscriber ID 18. * / 19. Private String IMSI; 20. Private Context cxt; 21. Public PhoneInfo (Context context) {22. Cxt=context; 23. TelephonyManager = (TelephonyManager) context 24. .getSystemService (Context.TELEPHONY_SERVICE); 25. } 26. twenty-seven。 / * 28. * get the phone number 29. * / 30. Public String getNativePhoneNumber () {31. String NativePhoneNumber=null; 32. NativePhoneNumber=telephonyManager.getLine1Number (); 33. Return NativePhoneNumber; 34. } 35. thirty-six。 / * 37. * obtain information about mobile phone service providers 38. * / 39. Public String getProvidersName () {40. String ProvidersName = "NCMA"; 41. Try {42. IMSI = telephonyManager.getSubscriberId (); 43. / / the first three digits of the IMSI account are countries, followed by China Mobile in the last two digits 0002, China Unicom 01 and China Telecom 03. forty-four。 System.out.println (IMSI); 45. If (IMSI.startsWith ("46000") | | IMSI.startsWith ("46002")) {46. ProvidersName = China Mobile; 47. } else if (IMSI.startsWith ("46001")) {48. ProvidersName = China Unicom; 49. } else if (IMSI.startsWith ("46003")) {50. ProvidersName = China Telecom; 51. } 52. } catch (Exception e) {53. E.printStackTrace (); 54. } 55. Return ProvidersName; 56. } 57. fifty-eight。 Public String getPhoneInfo () {59. TelephonyManager tm = (TelephonyManager) cxt.getSystemService (Context.TELEPHONY_SERVICE); 60. StringBuilder sb = new StringBuilder (); 61. sixty-two。 Sb.append ("\ nDeviceId (IMEI) =" + tm.getDeviceId ()) 63. Sb.append ("\ nDeviceSoftwareVersion =" + tm.getDeviceSoftwareVersion ()); 64. Sb.append ("\ nLine1Number =" + tm.getLine1Number ()) 65. Sb.append ("\ nNetworkCountryIso =" + tm.getNetworkCountryIso ()) 66. Sb.append ("\ nNetworkOperator =" + tm.getNetworkOperator ()) 67. Sb.append ("\ nNetworkOperatorName =" + tm.getNetworkOperatorName ()) 68. Sb.append ("\ nNetworkType =" + tm.getNetworkType ()) Sb.append ("\ nPhoneType =" + tm.getPhoneType (); 70. Sb.append ("\ nSimCountryIso =" + tm.getSimCountryIso ()); 71. Sb.append ("\ nSimOperator =" + tm.getSimOperator ()); 72. Sb.append ("\ nSimOperatorName =" + tm.getSimOperatorName ()) 73. Sb.append ("\ nSimSerialNumber =" + tm.getSimSerialNumber ()); 74. Sb.append ("\ nSimState =" + tm.getSimState ()); 75. Sb.append ("\ nSubscriberId (IMSI) =" + tm.getSubscriberId ()) 76. Sb.append ("\ nVoiceMailNumber =" + tm.getVoiceMailNumber ()) 77. Return sb.toString (); 78. } 79.}
Step 3: add to the startup Activity,JinshanTestActivity, call the code:
1.package com.jinshan.test; 2. 3.import android.app.Activity; 4.import android.os.Bundle; 5. 6.public class JinshanTestActivity extends Activity {7. / * Called when the activity is first created. * / 8. @ Override 9. Public void onCreate (Bundle savedInstanceState) {10. Super.onCreate (savedInstanceState); 11. SetContentView (R.layout.main); 12. 13. PhoneInfo siminfo = new PhoneInfo (JinshanTestActivity.this); 14. System.out.println ("getProvidersName:" + siminfo.getProvidersName ()); 15. System.out.println ("getNativePhoneNumber:" + siminfo.getNativePhoneNumber ()) 16. System.out.println ("- -"); 17. System.out.println ("getPhoneInfo:" + siminfo.getPhoneInfo ()); 18.} 19. 20. 21. 22.}
The fourth step, use the USB cable to connect the phone to the computer, ensure connectivity, and start running the project.
Finally, let's look at the LOGCAT log and the results are as follows:
04-01 16 2015 57.105: I/System.out (952): 460003121934674
04-01 16-20 57.105: I/System.out: getProvidersName: China Mobile
04-01 16-20 57.115: I/System.out (952): getNativePhoneNumber:136XXXXXXX
04-01 16-20-57.115: I/System.out:
04-01 16-20-5-7. 145: I/System.out: getPhoneInfo:
04-01 16 IMEI 20 15: I/System.out (952): DeviceId (IMEI) = 352XXXXXXXX61328
04-01 16 20 57.145: I/System.out 952: DeviceSoftwareVersion = 01
04-01 16 136XXXXXXX 20 57.145: Line1Number = 136XXXXXXX
04-01 16 cn 20 57.145: NetworkCountryIso = cn
04-01 16-20 57.145: I/System.out: NetworkOperator = 46000
04-01 16 20 57.145: I/System.out: 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 cn 20 57.145: SimCountryIso = cn
04-01 16-20 57.145: I/System.out: SimOperator = 46000
04-01 16 CMCC 20 57.145: SimOperatorName = CMCC
04-01 16 898xxxxxx90108 20 57.145: SimSerialNumber = 898xxxxxx90108
04-01 16-20 57.145: I/System.out: SimState = 5
04-01 16 IMSI 20 15: I/System.out (952): SubscriberId (IMSI) = 46000xxxxxxxx4674
So let's explain exactly what the above information means.
The mobile phone number obtained by getNativePhoneNumber
DeviceId (IMEI) mobile phone international mobile subscriber identification number
NetworkOperator Mobile operator number
NetworkOperatorName Mobile operator name
SimSerialNumber SimOperator SimCountryIso SimSerialNumber SubscriberId (IMSI) some details about mobile phone SIM card
In fact, the operation of obtaining System.ANDROID_ID is not written in the code, because many mobile devices cannot get andnroid_id.
Of course, today we mainly talk about the mobile device information and mobile phone number that we can get by using this permission alone.
If you want to get more information about WIFI, Bluetooth, GPS, read and write SDCARD, you need to add other permissions.
In addition, in this test, I can get the mobile phone number with my own mobile phone SIM card test, of course, some mobile phone numbers are not available, and here are the reasons for it.
Not all mobile phone numbers are available. Only part of it is available.
This is because the mobile operator does not write the data of the mobile phone number into the sim card. The SIM card has only a unique number for the network and devices to identify that is the IMSI number, the mobile phone signal can also be said to be transmitted through this number in the network, not the mobile phone number. Just imagine, after your SIM is lost, will you reissue a new one and change your number? No, it won't. This is because the IMSI number corresponding to your mobile phone number has been changed to the IMSI number of the new SIM card in the mobile operator.
So why can some mobile phone numbers be displayed?
This is like a variable, and when the mobile operator assigns a value to it, it naturally has a value. If you don't assign a value, it will be empty.
For mobile users, the mobile phone number (MDN) is saved in the operator's server, not in the SIM card. The SIM card retains only IMSI and some authentication information. Every time the mobile phone enters the network to register, it will upload the IMSI and verification information to the operator's server in the form of SMS. After completing the registration action, the server will send the registration result to the mobile phone in the form of SMS. The content of the distribution will vary according to different conditions.
If the server does not include the phone number in the text message, the phone cannot get the phone number. If the message contains a number, the phone will cache it for other use. In addition, for other operators' SIM cards or UIM cards, MDN may be saved in UIM cards. It is impossible to get a local number at 100%.
Mobile Shenzhou Bank, Unicom's card is available. The dynamic zone is not available. Other cards haven't been tried yet.
If you can read the SIM card number, there should be a premise. That is, the SIM card has been written to the local number, otherwise it cannot be read.
This is the end of this article on "the code example of android Android app to obtain mobile device information and mobile phone number". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.