Junaid Ahmad
Junaid Ahmad

Reputation: 53

How to get Sim Operator Name from Dual Sim Android Device.?

I have Dual Sim Android smartphone. I know there is no support for Dual Sim device in android SDK. I want to access a sim operator name of sim on default slot. But when I run program it gives me an empty string. Following is my code:

TelephonyManager telemamanger = (TelephonyManager) 
getSystemService(Context.TELEPHONY_SERVICE);

String simOperatorName = telemamanger.getSimOperatorName();      
Toast.makeText(AmountActivity.this,simOperatorName,Toast.LENGTH_SHORT).show();

Upvotes: 4

Views: 6416

Answers (3)

Lakpriya Senevirathna
Lakpriya Senevirathna

Reputation: 5129

This is the full code to get sim names for any android devices.

//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();
    }

Upvotes: 3

Atiar Talukdar
Atiar Talukdar

Reputation: 746

// To Get System TELEPHONY service ref
TelephonyManager tManager = (TelephonyManager) getBaseContext()
      .getSystemService(Context.TELEPHONY_SERVICE);

// Get Mobile No 
String pNumber= tManager.getLine1Number();

// Get carrier name (Network Operator Name)
String networkOperatorName= tManager.getNetworkOperatorName();

Upvotes: 0

ghiath
ghiath

Reputation: 159

Try this instead:

telemamanger.getNetworkOperator() 

Upvotes: 2

Related Questions