How do I change the Mobile Country Code (MCC) in the Android Emulator?
Asked Answered
C

6

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?

Cory answered 14/4, 2010 at 13:15 Comment(0)
D
18

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.

Dubbin answered 27/5, 2016 at 13:2 Comment(8)
This works! Great tip too checking which props can be set! ThanksPrognosis
this doesn't work for me, if I do a getprop immediately after setprop I still get "us". Any idea why?Kowal
@AlexandruCristescu This is on an emulator?Dubbin
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.Blancmange
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.Subgroup
Fine! Thanks so much!Edelstein
setprop: failed to set property 'gsm.operator.iso-country' to 'no'Hade
The latest version of the Android emulator does not have 'su', so this no longer works.Electuary
P
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.

Protagonist answered 19/4, 2018 at 13:15 Comment(2)
The latest version of the Android emulator does not have 'su', so this no longer works.Electuary
su: inaccessible or not foundThreat
I
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.

Invocate answered 14/4, 2010 at 14:31 Comment(2)
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.Cory
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.Invocate
C
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.

Cupronickel answered 18/5, 2010 at 0:40 Comment(1)
While I totally agree with said, this does not answer the actual question.Forging
K
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.

Klehm answered 26/8, 2015 at 10:10 Comment(0)
M
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.

Micrometeorite answered 10/11, 2015 at 15:8 Comment(1)
The property is set, but I don't think this works - TelephonyManager does not read this property when returning getSimCountryIso() afaikDubbin

© 2022 - 2024 — McMap. All rights reserved.