3

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();
Dimitar
  • 4,402
  • 4
  • 31
  • 47
Junaid Ahmad
  • 43
  • 1
  • 6

3 Answers3

3

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();
    }
Lakpriya Senevirathna
  • 2,488
  • 2
  • 17
  • 35
2

Try this instead:

telemamanger.getNetworkOperator() 
Undo
  • 25,519
  • 37
  • 106
  • 129
ghiath
  • 159
  • 11
  • While this may answer the OP's question, this answer would be much more useful if you explain how and why it solves the problem and doesn’t introduce others. – Mifeet Apr 24 '16 at 10:24
0
// 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();
Atiar Talukdar
  • 668
  • 11
  • 22