看起来它已经预设为mcc310(美国)。我可以通过
TelephonyManager.getSimCountryIso()
或使用资源文件夹如res/values-mcc123/
读取这个值,但是我该如何在模拟器中设置这个值呢?TelephonyManager.getSimCountryIso()
或使用资源文件夹如res/values-mcc123/
读取这个值,但是我该如何在模拟器中设置这个值呢?要更改TelephonyManager.getSimCountryIso()
返回的内容,只需执行以下操作
adb shell setprop gsm.sim.operator.iso-country no
现在它不返回任何值(挪威)。
如果你想改变TelephonyManager.getSimOperator()
返回的值(MCC+MNC),那么执行
adb shell setprop gsm.sim.operator.numeric 24201
你已将MCC更改为242(挪威),将MNC更改为01(Telenor)。
要查看您可以更改哪些其他属性,请执行以下操作
adb shell getprop
已验证此方法适用于AVD和Genymotion。但是,这并不会使这些属性持久化。
我发现在一些API级别中,这些属性的值是不同的。我尝试解决了这个问题。
你可以使用以下命令在API 26上更改该值:
adb shell
su
setprop gsm.operator.numeric 280701
注意:有些模拟器需要重新启动。
在一些模拟器上,该属性的名称可能不同。
你可以按照以下步骤查找属性名称:
adb shell
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 <property name> <new MCC MNC>
。
您还可以使用getProp
来验证值是否已更改。
在模拟器中更改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
重启模拟器。
在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
在模拟器上:进入“设置” ->“无线和网络” ->“移动网络” ->“接入点名称”。尝试更改设置APN中的MCC值,然后再尝试您的代码。
adb shell
、su
启动shell,然后尝试@EspenRiskedal在他的帖子中提出的建议。对我来说,这样做是有效的——如果没有超级用户权限,它就不起作用。 - PattaFeuFeu