【问题标题】:get sim country ISO from multiple sim devices and e-sim devices从多个 sim 设备和 e-sim 设备获取 sim 国家 ISO
【发布时间】:2019-12-05 10:27:58
【问题描述】:

在通常情况下,如果用户的设备是物理 SIM 卡,我将通过以下代码获取国家/地区文化代码:

TelephonyManager manager = (TelephonyManager) cxt.getSystemService(Context.TELEPHONY_SERVICE);
    //getNetworkCountryIso
    if (manager != null && manager.getSimCountryIso() != null) {
        return manager.getSimCountryIso().toLowerCase();
    }

但是当设备中有 2 个模拟人生时,上面的代码会发生什么?以及当设备持有 e-sim 而不是物理 sim 时,我将如何获得国家 ISO 代码。

【问题讨论】:

    标签: android telephony country-codes


    【解决方案1】:

    您的代码获取位于插槽 1 的 SIM 的国家/地区 ISO,它不会关心其他 SIM 插槽。

    为了读取所有的 SIM 卡插槽,通过调用 SubscriptionManager.getSubscriptionId() 获取 SIM 订阅,这将返回一个 subscription ID's 的数组 我们知道 Android 多 SIM 卡支持完全基于制造商,在 Google android 中,如果双/多 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());
          }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-08
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多