Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

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();
like image 678
Junaid Ahmad Avatar asked Oct 17 '25 01:10

Junaid Ahmad


2 Answers

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();
    }
like image 112
Lakpriya Senevirathna Avatar answered Oct 19 '25 13:10

Lakpriya Senevirathna


Try this instead:

telemamanger.getNetworkOperator() 
like image 23
ghiath Avatar answered Oct 19 '25 13:10

ghiath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!