如何在 CDMA 网络下检索 Android 设备的国家代码信息?
对于所有其他人,您可以只使用 TelephonyManager为此:
String countryCode = null;
TelephonyManager telMgr = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if (telMgr.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA)
countryCode = telMgr.getNetworkCountryIso();
}
else {
// Now what???
}
我搜索了一下,但没有找到任何有用的信息来找到答案。
一些想法:
可以使用这些还是有更好的?
最佳答案
我找到了解决这个问题的方法...如果是 CDMA 手机,那么手机总是具有与 GSM 中的 SIM 卡相当的 ICC 硬件。
您所要做的就是使用与硬件关联的系统属性。以编程方式,您可以使用 Java 反射来获取此信息。与 GSM 设备不同,这是不可更改的,即使系统已获得 root 权限也是如此。
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
关于android - 如何获取 CDMA Android 设备的国家/地区代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8292287/