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