"Tool class" to get the phone SIM card operator

Source: Internet
Author: User

Join permission:<uses-permission android:name= "Android.permission.READ_PHONE_STATE" />

1  PackageCom.example.textphone;2 3 ImportAndroid.content.Context;4 ImportAndroid.telephony.TelephonyManager;5 6  Public classSimcardinfo {7     /**8 * Telephonymanager provides access to information on the device for communication services. Applications can use this class of methods to determine the access information of telecommunications providers and countries as well as certain types of users. 9 * Application can also register a listener to the change of the phone receiving state. Do not need to instantiate this class directlyTen * Use Context.getsystemservice (context.telephony_service) to get an instance of this class.  One      */ A     PrivateTelephonymanager Telephonymanager; -     /** - * International Mobile Subscriber Identification Code the      */ -     PrivateString IMSI; -  -      PublicSimcardinfo (Context context) { +Telephonymanager =(telephonymanager) Context - . Getsystemservice (context.telephony_service); +     } A  at     /** - * Role: Get the current settings of the phone number <BR> - * date:2012-3-12 <BR> - * This is not available at this time because of mobile policy issues -      */ -      PublicString Getnativephonenumber () { inString Nativephonenumber = ""; -Nativephonenumber =Telephonymanager.getline1number (); to         returnNativephonenumber; +     } -  the     /** * * role:telecom service providers get mobile service information <BR> $ * requires permission to join <uses-permissionPanax Notoginseng * android:name= "Android.permission.READ_PHONE_STATE"/> <BR> -      */ the      PublicString Getprovidersname () { +String Providersname =NULL; A         //returns a unique user ID; That's the number of the card. God of Horses theIMSI =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.  - //log.i ("tag", IMSI); $         if(IMSI = =NULL|| "". Equals (IMSI)) { $Providersname = "Failed to get mobile number"; -}Else -             if(Imsi.startswith ("46000") | | Imsi.startswith ("46002")) { theProvidersname = "China Mobile"; -}Else if(Imsi.startswith ("46001")) {WuyiProvidersname = "China Unicom"; the}Else if(Imsi.startswith ("46003")) { -Providersname = "China Telecom"; Wu         } -         returnProvidersname; About     } $  -}

The following is then called in the event:

1Simcardinfo Siminfo =NewSimcardinfo (mainactivity. This);2 if(v = = Button_getsiminfo && Siminfo! =NULL) {3LOG.I ("tag", "~ ~ ~ ~ ~ ~ ~ ~" +siminfo.getprovidersname ());4 //log.i ("tag", "~~~~~ number ~~~~~" + siminfo.getnativephonenumber ());5 //Number.settext (Siminfo.getnativephonenumber ());6 Privoid.settext (Siminfo.getprovidersname ());7}Else {8Toast.maketext (mainactivity. This, "Data acquisition failed!" ",
Toast.length_long). Show ();9 }

Function description

Getcelllocation () returns the cell position of the appliance access_coarse_location or access_fine_location

Getdeviceid () returns the Imei/meid device. If the device is a GSM device then the IMEI number will be returned if the device is a CDMA device then Meid will be returned read_phone_state

Getline1number () returns the phone number of the device (MSISDN number) read_phone_state

Getnetworkoperatorname () returns the name of the registered network operator

Getnetworkoperator () back to MCC + registered network operator of multinational companies

Getnetworkcountryiso () returns the country code of the registered network operator

Getsimcountryiso () returns the SIM card operator's country code read_phone_state

Getsimoperator () returns the number of individual nuclear cells of the SIM card operator + metallurgical read_phone_state

Getsimoperatorname () returns the name of the SIM card operator Read_phone_state

Getsimserialnumber () returns the serial number of the SIM card read_phone_state

Getnetworktype () returns the type of network device available. This will be one of the following values:

Telephonymanager.network_type_unknown

Telephonymanager.network_type_gprs

Telephonymanager.network_type_edge

Telephonymanager.network_type_umts read_phone_state

Getphonetype () returns the type of the device.

This will be one of the following values:

Telephonymanager.phone_type_none

telephonymanager.phone_type_gsm

TELEPHONYMANAGER.PHONE_TYPE_CDMA read_phone_state

Getsubscriberid () returns the device of the user ID (IMSI) read_phone_state

Getneighboringcellinfo () Returns the information of the Neighboringcellinfo class representing the neighboring cell, or returns NULL if available Access_coarse_updates

Tool class get carrier for phone SIM card

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.