Get country based on GSM/UMTS network
I need to detect the MCC of the country in which the GSM/UMTS wireless modem is currently开发者_运维问答 now.
Based on GSM networks
You need to use
getSimCountryIso()
andgetNetworkCountryIso()
from the TelephonyManagerReturns the ISO country code equivalent for the SIM provider's country code.
Based on WIFI you use a Ip to Country database
You have also the option to use the Geocoder class based on the location
First get the MCC/MNC:
TelephonyManager tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String networkOperator = tel.getNetworkOperator();
if (networkOperator != null) {
int mcc = Integer.parseInt(networkOperator.substring(0, 3));
int mnc = Integer.parseInt(networkOperator.substring(3));
}
Then, based on that, you can get the number corresponding to the selected MCC. There are plenty of lists on the internet, for example this one on Wikipedia
精彩评论