get both simcard operator name in dual SIM mobile

前端 未结 5 1594
不思量自难忘°
不思量自难忘° 2021-01-06 09:10

I want to know Both sim card\'s operator name when mobile is dual sim.In single SIM I got operator name programmatically But For duel SIM I can\'t although after so many sea

5条回答
  •  广开言路
    2021-01-06 10:13

    For any android device. This may help you. try this!

       //above 22
     if (Build.VERSION.SDK_INT > 22) {
            //for dual sim mobile
            SubscriptionManager localSubscriptionManager = SubscriptionManager.from(this);
    
            if (localSubscriptionManager.getActiveSubscriptionInfoCount() > 1) {
             //if there are two sims in dual sim mobile
                List localList = localSubscriptionManager.getActiveSubscriptionInfoList();
                SubscriptionInfo simInfo = (SubscriptionInfo) localList.get(0);
                SubscriptionInfo simInfo1 = (SubscriptionInfo) localList.get(1);
    
                final String sim1 = simInfo.getDisplayName().toString();
                final String sim2 = simInfo1.getDisplayName().toString();
    
            }else{
             //if there is 1 sim in dual sim mobile
                TelephonyManager tManager = (TelephonyManager) getBaseContext()
                        .getSystemService(Context.TELEPHONY_SERVICE);
    
                String sim1 = tManager.getNetworkOperatorName();
    
            }
    
        }else{
            //below android version 22
                    TelephonyManager tManager = (TelephonyManager) getBaseContext()
                            .getSystemService(Context.TELEPHONY_SERVICE);
    
                    String sim1 = tManager.getNetworkOperatorName();
        }
    

提交回复
热议问题