Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从双卡手机Android获取运营商名称?_Java_Android - Fatal编程技术网

Java 如何从双卡手机Android获取运营商名称?

Java 如何从双卡手机Android获取运营商名称?,java,android,Java,Android,我可以从duel SIM手机中获取运营商名称 TelephonyManager telephonyManager = ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE)); 我使用了以下代码,但它只适用于单SIM手机 TelephonyManager telephonyManager = ((TelephonyManager) mContext.getSystemService(Context.TEL

我可以从duel SIM手机中获取运营商名称

TelephonyManager telephonyManager = ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE));
我使用了以下代码,但它只适用于单SIM手机

TelephonyManager telephonyManager = ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE));

因为android不支持至少低于API级别22的多个sim卡

从API 22开始,您可以使用SubscriptionManager的方法getActiveSubscriptionInfo()检查多个SIM。更多详细信息

有关更多详细信息,请参阅下面的链接

使用“SubscriptionManager”,我们可以知道android手机双sim卡的运营商名称

SubscriptionManager subscriptionManager=(SubscriptionManager)getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);

            List<SubscriptionInfo> subscriptionInfoList=subscriptionManager.getActiveSubscriptionInfoList();

            if(subscriptionInfoList!=null && subscriptionInfoList.size()>0){
               for(SubscriptionInfo info:subscriptionInfoList){
                  String carrierName = info.getCarrierName().toString();
                   String mobileNo=info.getNumber();
                   String countyIso=info.getCountryIso();
                   int dataRoaming=info.getDataRoaming();

               }

            }
SubscriptionManager SubscriptionManager=(SubscriptionManager)getSystemService(Context.TELEPHONY\u SUBSCRIPTION\u服务);
List SubscriptionInfo列表=subscriptionManager.GetActiveSubscriptionInfo列表();
if(subscriptionInfoList!=null&&subscriptionInfoList.size()>0){
对于(订阅信息:订阅信息列表){
字符串carrierName=info.getCarrierName().toString();
字符串mobileNo=info.getNumber();
字符串countyIso=info.getCountryIso();
int dataRoaming=info.getDataRoaming();
}
}

幸运的是,在寻找网络运营商的方法时,我找到了几种本机解决方案

对于API>=17:

TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

// Get information about all radio modules on device board
// and check what you need by calling #getCellIdentity.

final List<CellInfo> allCellInfo = manager.getAllCellInfo();
for (CellInfo cellInfo : allCellInfo) {
    if (cellInfo instanceof CellInfoGsm) {
        CellIdentityGsm cellIdentity = ((CellInfoGsm) cellInfo).getCellIdentity();
        //TODO Use cellIdentity to check MCC/MNC code, for instance.
    } else if (cellInfo instanceof CellInfoWcdma) {
        CellIdentityWcdma cellIdentity = ((CellInfoWcdma) cellInfo).getCellIdentity();
    } else if (cellInfo instanceof CellInfoLte) {
        CellIdentityLte cellIdentity = ((CellInfoLte) cellInfo).getCellIdentity();
    } else if (cellInfo instanceof CellInfoCdma) {
        CellIdentityCdma cellIdentity = ((CellInfoCdma) cellInfo).getCellIdentity();
    } 
}

看看这个,这可能有助于了解getcarriername()和getdisplayname()之间的区别。当飞机模式打开时,我没有得到作为运营商名称的服务,而获取显示名称作为Airtel。我想询问使用哪种方式向用户显示SIM卡操作员姓名。getcarriername()和getdisplayname()之间的区别是什么。当飞机模式打开时,我没有得到作为运营商名称的服务,而获取显示名称作为Airtel。我想询问使用哪种方式向用户显示SIM卡运营商名称。
final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
final List<SubscriptionInfo> activeSubscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
for (SubscriptionInfo subscriptionInfo : activeSubscriptionInfoList) {
    final CharSequence carrierName = subscriptionInfo.getCarrierName();
    final CharSequence displayName = subscriptionInfo.getDisplayName();
    final int mcc = subscriptionInfo.getMcc();
    final int mnc = subscriptionInfo.getMnc();
    final String subscriptionInfoNumber = subscriptionInfo.getNumber();
}
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if (manager.getPhoneCount() == 2) {
    // Dual sim
}