Android gets SIM card carrier Information
Telephonymanager TM = (telephonymanager) Context. getsystemservice (context. telephony_service );
Use of telephonymanager
Telephonymanager provides the entry for obtaining Communication Service Information on the device. The application uses this method to obtain the service provider or status of the phone. The program can also register a listener to listen for changes in the phone status.
You do not need to instantiate this class directly. Use context. getsystemservice (context. telephony_service) to obtain the instance of this class.
Note: Some phone information requires the appropriate permissions.
Invalid Method
Getsimoperatorname ()
Returns the service provider name (SPNs). // obtain the service provider name, such as China Telecom, China Unicom, and China Mobile.
Use the following method
Method 1:
Obtain the imsi code of the mobile phone and determine whether it is China Mobile/China Unicom/China Telecom
Telephonymanager telmanager = (telephonymanager) getsystemservice (context. telephony_service );
/** Get the imsi code of the SIM card
* Unique SIM card ID: imsi International Mobile User identification code (imsi: International Mobile Subscriber identification number) is the identifier for distinguishing mobile users,
* It is stored in the SIM card and can be used to distinguish valid information of mobile users.
Imsi is composed of MCC, MNC, and msin. MCC is a mobile country number and consists of three digits,
* The only country that identifies a mobile customer is China's 460. the MNC is the network ID, which consists of two digits,
* It is used to identify the mobile network to which mobile customers belong. China Mobile is 00, China Unicom is 01, and China Telecom is 03;
Msin is a mobile customer identification code consisting of 11 digits.
*
Uniquely identifies China Mobile clients in China's GSM mobile communication network. To distinguish between mobile and Unicom, you only need to obtain the MNC field in the SIM card.
*/
String imsi = telmanager. getsubscriberid ();
If (imsi! = NULL ){
If (imsi. startswith ("46000") | imsi. startswith ("46002 ″))
{// Because imsi under mobile network number 46000 is used up, A 46002 number is virtualized, and this number is used in segment 134/159.
// China Mobile
} Else if (imsi. startswith ("46001 ″)){
// China Unicom
} Else if (imsi. startswith ("46003 ″)){
// China Telecom
}
}
Method 2
Telephonymanager telmanager = (telephonymanager) getsystemservice (context. telephony_service );
String operator = telmanager. getsimoperator ();
If (Operator! = NULL ){
If (operator. Equals ("46000") | Operator. Equals ("46002") | Operator. Equals ("46007 ″)){
// China Mobile
} Else if (operator. Equals ("46001 ″)){
// China Unicom
} Else if (operator. Equals ("46003 ″)){
// China Telecom
}
}
Add permissions to file androidmanifest. xml
For details about how to use other methods, see the method description in the API documentation telephonymanager.
In the file
Androidmanifest. xml
Add Permissions
<Uses-Permission Android: Name =
"Android. Permission. read_phone_state"/>
Telephonymanager Tel = (telephonymanager) Context
. Getsystemservice (context. telephony_service );
String simoperator = Tel. getsimoperator ();
Imsi has a total of 15 digits, and its structure is as follows:
MCC + MNC + min
MCC: Mobile country code, mobile country code, 3 digits in total, 460 for China;
MNC: mobile network code, mobile network code, two digits in total, China Telecom 03, China Mobile 02, China Unicom GSM 01, a typical imsi Number of 460030912121001;
Min has a total of 10 digits, and its structure is as follows:
09 + m0m1m2m3 + ABCD
Among them, the m0m1m2m3 and the h0h1h2h3 in the mdn number can have a correspondence relationship, and the four bits of ABCD are freely allocated.
We can see that imsi has added MCC before the min number to differentiate the countries where each user is from, so that it can implement international roaming. In the same country, if there are multiple CDMA operators, they can be differentiated through MNC.
Function Description
Device for the location of the cell returned by getcelllocation ()
Access_coarse_location or access_fine_location
The IMEI/meid device returned by getdeviceid. If the device is a GSM device
Then the IMEI number will be returned. If the device is a CDMA device, then the 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 Carrier.
MCC + registered network operators of multinational corporations returned by getnetworkoperator ()
Getnetworkcountryiso () returns the country code of the registered Network Carrier.
Getsimcountryiso () returns the country code of the SIM card carrier.
Read_phone_state
Getsimoperator () returns the number of single-core cells of the SIM card operator +
Read_phone_state
Getsimoperatorname () returns the name of the SIM card carrier.
Read_phone_state
Getsimserialnumber () returns the serial number of the SIM card
Read_phone_state
Getnetworktype () returns the available types of network devices. 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 device type. This will be one of the following values:
Telephonymanager. phone_type_none
Telephonymanager. phone_type_gsm
Telephonymanager. phone_type_cdma
Read_phone_state
Getsubscriberid () the device that returns the user ID (imsi)
Read_phone_state
Getneighboringcellinfo () returns the neighboringcellinfo class representative list
Information of adjacent cells. If available
Returns null.
Access_coarse_updates