My Android application needs to react differently to different Mobile Country Codes.
It seems like it is hardcoded to mcc310 (US). I can read this value from TelephonyManager.getSimCountryIso()
or by using a resource folder like res/values-mcc123/
but how do I set this value in the emulator?
Changing MCC+MNC in the emulator can only be done with ADB. To change the MCC+MNC in the emulator, connect to ADB do the following
Then put your country code there. 23801 is danish coutry code.
For Droid4X emulator, it is
Reboot the emulator.
To change what
TelephonyManager.getSimCountryIso()
returns, simply executeand it now returns no (Norway).
If you want to change what
TelephonyManager.getSimOperator()
returns (MCC+MNC) then executeand you have changed MCC to 242 (Norway) and MNC to 01 (Telenor).
To see which other properties you can change then execute
This is verified to work on both AVD and Genymotion. However, this does not change these properties persistently.
Do know that relying on an MCC is not always correct in every country. Digicell for instance use one MCC+MNC in several countries. Also understand that the whole idea of an MCC is rather ludicrous from an network point of view. It is rather irrelevant to know if you're in Germany or in the Netherlands if both times you're on T-Mobile with an AT&T handset.
On emulator: go to Settings->WireLess and Network->Mobile Network->Access Point Names. Try changing MCC value in the set APN and then try your code.
I have observed that value for this properties varies in some API level. I have tried to address this issue.
You can use following command to change the value on API 26:
adb shell
su
setprop gsm.operator.numeric 280701
Note: Some emulators require restart.
On some emulators the property can be different name
You can find the property name as follows:
adb shell
getprop
It will give you data similar to following:
Search for
numeric
by copying the output in text file. Get the property name and usesetprop <property name> <new MCC MNC>
You can also use
getProp
to verify whether the value has been changed.It doesn't seem to be possible to change MCC/MNC via settings on the Android emulator, every time this is attempted the preconfigured "T-Mobile" APN will disappear from the list and network connectivity is lost. I've even had the emulator spontaneously reboot after a change.
The programmatic way doesn't work either, the APN will disappear right after:
It could be possible by hacking the emulator in the same ways that allow to change the MSISDN or IMEI, though.