How can I get the country code for CDMA Android devices?

后端 未结 3 983
谎友^
谎友^ 2020-12-06 22:44

How can I retrieve the country code information for Android devices under CDMA networks?

For all others, you can just use the TelephonyManager for that:



        
3条回答
  •  -上瘾入骨i
    2020-12-06 23:33

    I found a way to tackle this problem... If it is a CDMA phone, then the phone always has ICC hardware comparable to SIM cards in GSM.

    All you have got to do is use the system properties associated with the hardware. Programmatically, you can use Java reflection to get this information. This is not changeable, even if the system is rooted, unlike a GSM device.

    Class c = Class.forName("android.os.SystemProperties");
    Method get = c.getMethod("get", String.class);
    
    // Gives MCC + MNC
    String homeOperator = ((String) get.invoke(c, "ro.cdma.home.operator.numeric"));
    String country = homeOperator.substring(0, 3); // The last three digits is MNC
    

提交回复
热议问题