在通常情况下,当用户的设备具有物理SIM卡时,我会通过以下代码获取国家/地区文化代码:
TelephonyManager manager = (TelephonyManager) cxt.getSystemService(Context.TELEPHONY_SERVICE);
//getNetworkCountryIso
if (manager != null && manager.getSimCountryIso() != null) {
return manager.getSimCountryIso().toLowerCase();
}但是当设备中有两个sims时,上面的代码会发生什么呢?当设备持有电子SIM卡而不是实体SIM卡时,我如何获得国家ISO代码。
发布于 2020-05-08 14:47:23
你的代码会得到SIM卡的国家ISO,它位于插槽1,它不会关心其他SIM卡插槽。
为了读取所有的SIM卡插槽,通过调用SubscriptionManager.getSubscriptionId()获得SIM卡订阅,它将返回一组subscription ID's,因为我们知道安卓对多SIM卡的支持完全基于制造商,在谷歌安卓中,如果是双卡/多SIM卡,你可以更新你的TelephonyManager,如下所示:
subIds[] = SubscriptionManager.getSubscriptionIds(slotInex) //Pass slot index ex: 0,1 etc
for(int i=0;i<subIds.lenth();i++){
if (SubscriptionManager.isActiveSubscriptionId(subIds[i])){
TelephonyManager manager = telephonyManager.createForSubscriptionId(subIds[i]);
if (manager != null && manager.getSimCountryIso() != null) {
System.out.println(manager.getSimCountryIso().toLowerCase());
}
}
}https://stackoverflow.com/questions/59193086
复制相似问题