Android determines which mobile operator the SIM card belongs to, androidsim

Source: Internet
Author: User

Android determines which mobile operator the SIM card belongs to, androidsim

Method 1:
Obtain the IMSI code of the mobile phone and determine whether it is China Mobile, China Unicom, or China Telecom.

TelephonyManager telManager = (TelephonyManager) getSystemService (Context. TELEPHONY_SERVICE);/** get the IMSI code of the SIM card * unique ID of the SIM card: IMSI International Mobile User Identification code (IMSI: International Mobile Subscriber Identification Number) is the identifier that distinguishes Mobile users, * It is stored in the SIM card and can be used to distinguish valid information of mobile users. IMSI consists of MCC, MNC, and MSIN. Among them, MCC is a mobile country number consisting of three digits. * It uniquely identifies the country to which mobile customers belong, and China is 460; MNC is a network id consisting of two digits. * It is used to identify the mobile network to which a mobile customer belongs. 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 the domestic 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, section 134/159 uses this ID // 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") {// China Mobile} else if (operator. equals ("46001") {// China Unicom} else if (operator. equals ("46003") {// China Telecom }}

 

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.