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

Source: Internet
Author: User

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.

The domestic SIM card is IMSI number, no phone number exists on the machine. The operator assigns the number to you only after you have contacted the base station.


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. Applications can use this class of methods to determine the access information of telecommunications providers and countries as well as certain types of users. * Application can also register a listener to the change of the phone receiving state. 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;} /** * Get mobile service provider information need to join the rights <uses-permission * android:name= "Android.permission.READ_PHONE_STATE"/> * * @author Yazhizhao 20142014-10-22 am 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 = "unicom";} else if ( Imsi.startswith ("46003")) {providersname = "China 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 Ext Ends Activity {private TextView number;private TextView privoid;private String TAG = "mainactivity"; @Overridepublic void O Ncreate (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 ());}}

Operating effect:




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

Related Article

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.