16

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?

appersiano
  • 2,670
  • 22
  • 42
neu242
  • 15,796
  • 20
  • 79
  • 114

6 Answers6

16

To change what TelephonyManager.getSimCountryIso() returns, simply execute

adb shell setprop gsm.sim.operator.iso-country no

and it now returns no (Norway).

If you want to change what TelephonyManager.getSimOperator() returns (MCC+MNC) then execute

adb shell setprop gsm.sim.operator.numeric 24201

and you have changed MCC to 242 (Norway) and MNC to 01 (Telenor).

To see which other properties you can change then execute

adb shell getprop

This is verified to work on both AVD and Genymotion. However, this does not change these properties persistently.

Espen Riskedal
  • 1,425
  • 15
  • 28
  • This works! Great tip too checking which props can be set! Thanks – speedynomads Nov 03 '16 at 14:29
  • this doesn't work for me, if I do a getprop immediately after setprop I still get "us". Any idea why? – Alexandru Cristescu Aug 23 '17 at 10:27
  • @AlexandruCristescu This is on an emulator? – Espen Riskedal Aug 23 '17 at 13:40
  • 2
    It might be necessary to use elevated privileges, i.e.: Start the shell using `adb shell`, `su`, and then try what @EspenRiskedal proposes in his post. Then it worked for me—without super-user privileges it did not. – PattaFeuFeu Sep 13 '17 at 14:01
  • This doesn't update the `Configuration` dimension `mcc`, which is seemingly what the Resources system uses to identify an alternative resource with an MCC qualifier. Using logging, I see `Configuration.mcc=310`, `TelephonyManager.getSimOperator()='40401'`. I created a resource file ` values-mcc404/values.xml` and was hoping to test the resource override for MCC 404. – androidguy Nov 27 '17 at 23:15
  • Fine! Thanks so much! – Alexey Nikitin Feb 14 '19 at 07:07
  • setprop: failed to set property 'gsm.operator.iso-country' to 'no' – Elia Weiss Feb 21 '22 at 08:00
  • 1
    The latest version of the Android emulator does not have 'su', so this no longer works. – Rasmusob Jun 16 '22 at 07:33
3

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:

  1. adb shell
  2. su
  3. 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:

  1. adb shell
  2. getprop

It will give you data similar to following:

...
[dalvik.vm.lockprof.threshold]: [500]
[dalvik.vm.stack-trace-file]: [/data/anr/traces.txt]
[dalvik.vm.usejit]: [true]
[dalvik.vm.usejitprofiles]: [true]
[debug.atrace.tags.enableflags]: [0]
[debug.force_rtl]: [0]
[dev.bootcomplete]: [1]
[drm.service.enabled]: [true]
[gsm.current.phone-type]: [1]
[gsm.defaultpdpcontext.active]: [true]
[gsm.network.type]: [LTE]
[gsm.nitz.time]: [1524141151210]
[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.baseband]: [1.0.0.0]
[gsm.version.ril-impl]: [android reference-ril 1.0]
[hwservicemanager.ready]: [true]
[init.svc.adbd]: [running]
[init.svc.audio-hal-2-0]: [running]
[init.svc.audioserver]: [running]
[init.svc.bootanim]: [stopped]
[init.svc.camera-provider-2-4]: [running]
[init.svc.cameraserver]: [running]
...

Search for numeric by copying the output in text file. Get the property name and use setprop <property name> <new MCC MNC>

You can also use getProp to verify whether the value has been changed.

Sagar
  • 23,903
  • 4
  • 62
  • 62
0

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.

Samuh
  • 36,316
  • 26
  • 109
  • 116
  • Good idea, but it didn't work. When I tried this the APN disappeared from the list, and my application couldn't access the network anymore. – neu242 Apr 14 '10 at 14:39
  • Well,in my case the APN did disappear and I got: "No Network connection" when I fired up the browser. But when I okayed the alert, I was able to surf the internet. Strange behavior. Anyways, you can do a "Reset to Default" on the APN page and get your earlier APN back. – Samuh Apr 14 '10 at 14:51
0

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.

0

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:

root@generic_x86:/ # content update --uri content://telephony/carriers/ --bind name:s:'TheAPN' --bind apn:s:apn.operator.net --bind numeric:i:12345 --bind user:s: --bind password:s: --bind server:s: --bind proxy:s: --bind mmsproxy:s: --bind mmsc:s: --bind type:s: --bind mcc:i:123 --bind mnc:i:45 --bind current:i:1 --where _id=1

It could be possible by hacking the emulator in the same ways that allow to change the MSISDN or IMEI, though.

Community
  • 1
  • 1
André Fernandes
  • 2,335
  • 3
  • 25
  • 33
0

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

adb -s 127.0.0.1:53001 shell

Then put your country code there. 23801 is danish coutry code.

setprop persist.<name of the emulator>.mccmnc 23801

For Droid4X emulator, it is

setprop persist.droid4x.mccmnc 23801

Reboot the emulator.

Melquiades
  • 8,496
  • 1
  • 31
  • 46
  • The property is set, but I don't think this works - TelephonyManager does not read this property when returning getSimCountryIso() afaik – Espen Riskedal May 27 '16 at 12:54