如何在 Android 模拟器中更改移动国家/地区代码 (MCC)?
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
要更改
TelephonyManager.getSimCountryIso()
返回的内容,只需执行即可,现在返回 no(挪威)。
如果您想更改
TelephonyManager.getSimOperator()
返回的内容 (MCC+MNC),则执行并将 MCC 更改为 242(挪威),将 MNC 更改为 01(Telenor)。
要查看您可以更改哪些其他属性,请执行
此操作已验证可在 AVD 和 Genymotion 上运行。然而,这不会持久地改变这些属性。
To change what
TelephonyManager.getSimCountryIso()
returns, simply executeand it now returns no (Norway).
If you want to change what
TelephonyManager.getSimOperator()
returns (MCC+MNC) then executeand you have changed MCC to 242 (Norway) and MNC to 01 (Telenor).
To see which other properties you can change then execute
This is verified to work on both AVD and Genymotion. However, this does not change these properties persistently.
我观察到此属性的值在某些 API 级别上有所不同。我已经尝试解决这个问题。
您可以使用以下命令更改 API 26 上的值:
adb shell
su
setprop gsm.operator.numeric 280701
注意:< /strong> 某些模拟器需要重新启动。
在某些模拟器上,属性可以是不同的名称
您可以按如下方式找到属性名称:
adb shell
getprop
它将为您提供类似于以下内容的数据:
搜索
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:
adb shell
su
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:
adb shell
getprop
It will give you data similar to following:
Search for
numeric
by copying the output in text file. Get the property name and usesetprop <property name> <new MCC MNC>
You can also use
getProp
to verify whether the value has been changed.在模拟器上:转到“设置”->“无线和网络”->“移动网络”->“接入点名称”。尝试更改设置的 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.
请注意,依赖 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.
似乎无法通过 Android 模拟器上的设置更改 MCC/MNC,每次尝试时,预配置的“T-Mobile”APN 都会从列表中消失,网络连接也会丢失。我什至让模拟器在更改后自动重新启动。
编程方式也不起作用,APN 将立即消失:
可以通过以允许更改 MSISDN 或 IMEI,不过。
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:
It could be possible by hacking the emulator in the same ways that allow to change the MSISDN or IMEI, though.
在模拟器中更改MCC+MNC只能使用ADB来完成。要更改模拟器中的 MCC+MNC,请连接到 ADB,执行以下操作,
然后将您的国家/地区代码放在那里。 23801 是丹麦国家代码。
对于Droid4X模拟器,就是
重启模拟器。
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
Then put your country code there. 23801 is danish coutry code.
For Droid4X emulator, it is
Reboot the emulator.