如何在 Android 模拟器中更改移动国家代码 (MCC)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2637606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:41:42  来源:igfitidea点击:

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

androidandroid-emulatormccmobile-country-code

提问by neu242

My Android application needs to react differently to different Mobile Country Codes.

我的 Android 应用程序需要对不同的移动国家/地区代码做出不同的反应。

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?

它似乎被硬编码为mcc310 (US)。我可以从TelephonyManager.getSimCountryIso()或使用资源文件夹读取此值,res/values-mcc123/但如何在模拟器中设置此值?

回答by Espen Riskedal

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

要更改TelephonyManager.getSimCountryIso()返回的内容,只需执行

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

and it now returns no (Norway).

现在它返回 no(挪威)。

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

如果你想改变什么TelephonyManager.getSimOperator()返回(MCC+MNC)然后执行

adb shell setprop gsm.sim.operator.numeric 24201

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

并且您已将 MCC 更改为 242(挪威)并将 MNC 更改为 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.

这经验证适用于 AVD 和 Genymotion。但是,这不会持续改变这些属性。

回答by Sagar

I have observed that value for this properties varies in some API level. I have tried to address this issue.

我观察到此属性的值在某些 API 级别有所不同。我试图解决这个问题。

You can use following command to change the value on API 26:

您可以使用以下命令更改 API 26 上的值:

  1. adb shell
  2. su
  3. setprop gsm.operator.numeric 280701
  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
  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 numericby copying the output in text file. Get the property name and use setprop <property name> <new MCC MNC>

numeric通过复制文本文件中的输出来搜索。获取属性名称并使用setprop <property name> <new MCC MNC>

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

您还可以使用getProp来验证该值是否已更改。

回答by prouser135

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

在模拟器中更改 MCC+MNC 只能通过 ADB 来完成。要在模拟器中更改 MCC+MNC,连接到 ADB 执行以下操作

adb -s 127.0.0.1:53001 shell

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

然后把你的国家代码放在那里。23801 是丹麦的国家代码。

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

For Droid4X emulator, it is

对于 Droid4X 模拟器,它是

setprop persist.droid4x.mccmnc 23801

Reboot the emulator.

重启模拟器。

回答by Samuh

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.

在模拟器上:转到设置->无线和网络->移动网络->接入点名称。尝试更改设置的 APN 中的 MCC 值,然后尝试您的代码。

回答by Raindeer

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.

请注意,在每个国家/地区,依赖 MCC 并不总是正确的。例如,Digicell 在几个国家使用一个 MCC+MNC。还要理解,从网络的角度来看,MCC 的整个想法是相当荒谬的。如果您两次都使用 AT&T 手机使用 T-Mobile,那么知道您是在德国还是在荷兰是无关紧要的。

回答by André Fernandes

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.

似乎无法通过 Android 模拟器上的设置更改 MCC/MNC,每次尝试更改时,预配置的“T-Mobile”APN 都会从列表中消失并且网络连接丢失。我什至让模拟器在更改后自发地重新启动。

The programmatic way doesn't work either, the APN will disappear right after:

编程方式也不起作用,APN 将在以下时间消失:

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 MSISDNor IMEI, though.

但是,可以通过以允许更改MSISDNIMEI的相同方式入侵模拟器。