Vaishali Goel
Vaishali Goel

Reputation: 85

Getting phone type information form Telephony Manager

I want to know how do I access the phone type info [whether it is GSM or CDMA] from TelephonyManager. which function can I use for this:

My code for this is :

SubscriptionManager sm = SubscriptionManager.from(context);

List<SubscriptionInfo> sil = sm.getActiveSubscriptionInfoList();
sim_value[0]= sil.get(0).getDisplayName().toString();
sim_value[1]= sil.get(0).getIccId().toString();
sim_value[2]= String.valueOf(sil.get(0).getSimSlotIndex());
sim_value[3]= sil.get(0).getCarrierName().toString();

Upvotes: 1

Views: 1381

Answers (2)

Vishal Thakkar
Vishal Thakkar

Reputation: 2127

You can achieve this using Telephony Manager

you must declare following permission in AndroidManifest file..

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Have an object of TelephonyMnager

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

Get the Phone Type CDMA/GSM/NONE

  int phoneType=tm.getPhoneType();

        switch (phoneType)
        {
                case (TelephonyManager.PHONE_TYPE_CDMA):
                           // your code
                               break;
                case (TelephonyManager.PHONE_TYPE_GSM) 
                           // your code                 
                               break;
                case (TelephonyManager.PHONE_TYPE_NONE):
                           // your code              
                                break;
         }

For more refer this Telephony Manager

Upvotes: 4

Abhishek Patel
Abhishek Patel

Reputation: 4328

Try this it may be help to you

final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) { 
    // device is 3G CDMA           
}
else if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) { 
   // device is 2G GSM         
}

Upvotes: 0

Related Questions