Android Get Carrier

Source: Internet
Author: User

Today received a new demand for the server to send the device operator name, and then my first reaction is that Umeng can not accurately statistics operators, how can I judge to send specific operators? Such as:


This picture reflects the name of the operator of the friend's cell phone, and what they look like. Is there any way to judge exactly what the operator is? For example, only "China Mobile", "Unicom", "Chinese telecom" are returned.
My solution here is to judge by the MCC/MNC code of the device.
First of all, we want to know what MCC/MNC is, see Wiki encyclopedia. Through reading, we can know that as long as the comparison of MCC/MNC coding, we can know what the specific carrier.
Next, is the specific code, as follows:

/** * return operator needs to join the <uses-permission android:name= "Android.permission.READ_PHONE_STATE"/> <BR> * * @return 1, representing China Mobile, 2, on behalf of China Unicom, 3, on behalf of Chinese Telecom, 0, representing unknown * @author [email protected] */  Public int getoperators(Context context) {//Mobile Network Code (English: Mobile networks CODE,MNC) is with the mobile device country code (country CODE,MCC) (also known as "MCC/        //MNC "), such as 46000, the first three are MCC, the latter two are MNC get mobile service information        intOperatorsname =0; String IMSI = (telephonymanager) context.getsystemservice (context.telephony_service). Getsubscriberid ();//IMSI front 3 bit 460 is country, followed by 2 bit 00 carrier CodeSystem.out.println (IMSI);if(Imsi.startswith ("46000") || Imsi.startswith ("46002") || Imsi.startswith ("46007") {Operatorsname =1; }Else if(Imsi.startswith ("46001") || Imsi.startswith ("46006") {Operatorsname =2; }Else if(Imsi.startswith ("46003") || Imsi.startswith ("46005") {Operatorsname =3; }returnOperatorsname; }

Through the client local comparison to MCC/MNC determine the operator this way, I do not agree with, I think the MCC/MNC on the server, the server to determine this is the best solution. Because the application is distributed, the code is dead, the future can not be extended, but the server can be dynamic, at any time to configure the MCC/MNC encoding.

Android Get Carrier

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.