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

发布于 2024-08-28 16:14:50 字数 204 浏览 7 评论 0原文

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

只是我以为 2024-09-04 16:14:50

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

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

,现在返回 no(挪威)。

如果您想更改 TelephonyManager.getSimOperator() 返回的内容 (MCC+MNC),则执行

adb shell setprop gsm.sim.operator.numeric 24201

并将 MCC 更改为 242(挪威),将 MNC 更改为 01(Telenor)。

要查看您可以更改哪些其他属性,请执行

adb shell getprop

此操作已验证可在 AVD 和 Genymotion 上运行。然而,这不会持久地改变这些属性。

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.

装纯掩盖桑 2024-09-04 16:14:50

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

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

  1. adb shell
  2. su
  3. setprop gsm.operator.numeric 280701

注意:< /strong> 某些模拟器需要重新启动。

在某些模拟器上,属性可以是不同的名称

您可以按如下方式找到属性名称:

  1. adb shell
  2. getprop

它将为您提供类似于以下内容的数据:

...
[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]
...

搜索numeric 通过复制文本文件中的输出。获取属性名称并使用 setprop;

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

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.

烟织青萝梦 2024-09-04 16:14:50

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

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.

一抹微笑 2024-09-04 16:14:50

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

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.

成熟稳重的好男人 2024-09-04 16:14:50

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

编程方式也不起作用,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

可以通过以允许更改 MSISDNIMEI,不过。

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.

土豪我们做朋友吧 2024-09-04 16:14:50

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

adb -s 127.0.0.1:53001 shell

然后将您的国家/地区代码放在那里。 23801 是丹麦国家代码。

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

对于Droid4X模拟器,就是

setprop persist.droid4x.mccmnc 23801

重启模拟器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文