Zhao Yazhi _android Get the native operator, the mobile phone number part can get

Source: Internet
Author: User

Mobile phone numbers are not all available. Only a part of it can be obtained.

This is because the mobile operator does not write data from the mobile phone number to the SIM card. The SIM card has only a unique number. For network and equipment identification that is the IMSI number, the cell phone signal can be said to pass through this number in the network, not mobile phone number.

Imagine. After your SIM is lost, do you want to replace a new one with a replacement number?

No, it is because the IMSI number in your mobile phone number is changed 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.


The domestic SIM card is IMSI number, no phone number exists on the machine. Only when you have contact with the base station. The operator assigns you the number.


But I also wrote a class implementation to get the operator

Layout file:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:layout_width= "Fill_ Parent "    android:layout_height=" fill_parent "    android:gravity=" center "    android:orientation=" vertical ">    <textview        android:id=" @+id/tv_num "        android:layout_width=" wrap_content "        android:layout _height= "Wrap_content"/>    <textview        android:id= "@+id/tv_privoid" android:layout_width= "Wrap_        Content "        android:layout_height=" wrap_content "/>    <button        android:id=" @+id/getsiminfo "        android:layout_width= "wrap_content"        android:layout_height= "wrap_content"        android:onclick= " Click "        android:text=" for information such as mobile phone number >    </Button></LinearLayout>


Simcardinfo.java:

/** * @author Yazhizhao * 20142014-10-22 morning 9:13:04 */package com.example.android_sms;import android.content.Context; Import Android.telephony.telephonymanager;import android.util.log;/** * @author Yazhizhao 20142014-10-22 9:13:04 */ public class Simcardinfo {/** * Telephonymanager provides access to information about the communication service on the device. The application is able to use this class of methods to identify the telecommunications service provider and the country as well as certain types of user access information. * The application is also able to register a listener-to-phone status change.

You do not need to instantiate this class directly using Context.getsystemservice (Context.telephony_service) to get an instance of this class. */private Telephonymanager telephonymanager;private String imsi;//International Mobile User Identification Code Public simcardinfo (context context) { Telephonymanager = (Telephonymanager) context.getsystemservice (context.telephony_service);} /** * Get the phone number currently set * * @author Yazhizhao 20142014-10-22 am 9:44:19 * @return */public string Getnativephonenumber () {string Nativephonenumber = null; Nativephonenumber = Telephonymanager.getline1number (); return nativephonenumber;} /** * Access to mobile service provider information need to increase permissions <uses-permission * android:name= "Android.permission.READ_PHONE_STATE"/> * * @author Yazhizhao 20142014-10-22 Morning 9:44:31 * @return */public string Getprovidersname () {String providersname = null;//Returns a unique user ID; That's the number of the card. Imsi = Telephonymanager.getsubscriberid ();//IMSI front 3 bit 460 is the country, followed by 2 bits 00 02 is China Mobile. 01 is China Unicom, 03 is Chinese telecom. LOG.I ("Mainactivity", "IMSI" + 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 =" telecom ";} return providersname;}}


Mainactivity.java

Package Com.example.android_sms;import Android.app.activity;import Android.os.bundle;import android.util.Log; Import android.view.view;import android.widget.textview;/** * Note Permissions <uses-permission android:name= " Android.permission.READ_PHONE_STATE "/> *  * @author Yazhizhao 20142014-10-22 morning 9:18:04 */public class Mainactivity extends Activity {private TextView number;private TextView privoid;private String TAG = "mainactivity"; @Over ridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main), number = (TextView) This.findviewbyid (r.id.tv_num);p rivoid = (TextView) This.findviewbyid ( r.id.tv_privoid);} public void Click (View v) {simcardinfo siminfo = new Simcardinfo (mainactivity.this); LOG.I (TAG, "operator" + siminfo.getprovidersname ()); LOG.I (TAG, "phone" + siminfo.getnativephonenumber ()), Number.settext (Siminfo.getnativephonenumber ());p Rivoid.settext ( Siminfo.getprovidersname ());}}

Execution effect:




Zhao Yazhi _android Get the native operator, the mobile phone number part can get

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.