Mastering Android Emulator SIM card
The Android emulator has improved a lot these years (for reference how it was before, see this old StackOverflow question).
Nowadays the emulator is much faster with better performance and with easy settings option.
Unfortunately, when it comes to SIM card settings, there aren’t any easy settings options, so we have to do it the ‘hard’ way using the ADB (Android Debug Bridge). If you want to know more about ADB before getting started you can have a look at some of my previous articles about ADB Part1, Part2, and Part3.
Let’s get started with SIM Properties
If you are using the TelephonyManager in your application to retrieve some pieces of information about the SIM card and if you want to test it in the emulator you are probably struggling with it.
The good news is that there is a way to change some of the default SIM card values returned from the emulator.
First of all, let’s get the system properties and filter the one related to the SIM Card. So go to your terminal (I am assuming you have ADB in your PATH) and simply type adb shell getprop | grep 'gsm'.
You probably get an output like this:
[gsm.current.phone-type]: [1]
[gsm.network.type]: [LTE]
[gsm.nitz.time]: [1581675852017]
[gsm.operator.alpha]: [Android]
[gsm.operator.iso-country]: [us]
[gsm.operator.isroaming]: [false]
[gsm.operator.numeric]: [310260]
[gsm.sim.operator.alpha]: [Android]
[gsm.sim.operator.iso-country]: [us]
[gsm.sim.operator.numeric]: [310260]
[gsm.sim.state]: [READY]
[gsm.version.ril-impl]: [android reference-ril 1.0]
Change SIM MCC/MNC
If you want to change the value returned from the emulator when you call TelephonyManager.getSimOperator() (returns the MCC+MNC of the provider of the SIM. 5 or 6 decimal digits) from your application we can do it by changing the property gsm.sim.operator.numeric
The MCC (Mobile Country Code) is used in combination with an MNC (Mobile Network Code) (also known as an “MCC/MNC tuple”), where the first 3 digits are related to the MCC and the last 2 to the MNC.
In order to make sure you insert a valid value for that property, you can go to https://www.mcc-mnc.com/ and choose a valid MCC/MNC tuple.
So in order to change gsm.sim.operator.numeric
property, just go the terminal again and set a new value for that system property:
adb shell su 0 setprop gsm.sim.operator.numeric 26801
In this case, I have set the MCC to Portugal and MNC to Vodafone. If you run the command: adb shell getprop | grep 'gsm'
, you will see the updated value.
Change SIM Country
And what about changing the SIM country code?
Yes, it is also possible! 🎉
In case you are using the TelephonyManager.getSimCountryIso() the SIM card country code value in the emulator can also be changed using the same technique.
In this case we need to use the property: gsm.sim.operator.iso-country
adb shell su 0 setprop gsm.sim.operator.iso-country pt
The country codes are represented by a two-letter code (ISO 3166–2 alpha), you can search for valid country codes in the official ISO site: https://www.iso.org/obp/ui/#search/code/
SIM Phone Number
Last but not least, let’s see how we can change the emulator phone number.
For this one, we cannot use the setprop
option through adb
like we have done in the previous steps.
At first glance it seemed there was no possibility to change the phone number in the emulator, but after some web digging I have found something in the official android-test Github repository that called my attention:
This was quite surprising 😯😱 since the official documentation of the Android Emulator — Start the emulator from the command line had no reference to this option…
So assuming you have in your PATH the emulator
executable we can do the following:
emulator @avd_name -phone-number 351123456789 -no-snapshot-load
We also use the option no-snapshot-load
to perform a cold boot so that the emulator shows the changes we have made, otherwise using the fast boot the changes the emulator will probably still show the old phone number.
I hope you enjoyed this post and that helps you in some way. Also, if you found it useful don’t hesitate in sharing across the community 👏 🙂