Does anyone know how to retrieve the country code information for Android devices under CDMA networks?
For all others, you can just use the TelephonyManager for that:
String countryCode = null;
TelephonyManager telMgr = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if (telMgr.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA)
countryCode = telMgr.getNetworkCountryIso();
}
else {
// Now what???
}
I searched a bit but did not find any useful information that would lead to an answer. Some ideas some to mind:
- GPS location: you can get the country from GeoCoder; and
- IP Address: there are some nice APIs to get it, such as ipinfodb.
Does anyone have done one of the approaches above, or implemented better ones?
Thanks for the help.
I found a way to tackle this problem .. if it is a CDMA phone , then the phone always has an ICC hardware comparable to SIM cards in GSM. All you gotta do is use the system properties associated with the hard ware . Programmatically you can use Java reflection to get this information . This is not changeable even system is rooted unlike GSM device.
It works for CDMA, but not always - depends on the network carrier.
Here's an alternative idea, which suggests looking at the Outgoing SMS or Calls to figure out this device's phone number, from which you can then figure out the CountryIso based on the international dialing code...
Hope this helps
based on @rana's reply, here's the full code, including safety and mapping to the ISO country code
I'm mapping just countries that actually use CDMA networks, based on this wiki page.