Getting phone type information form Telephony Manager

不羁的心 提交于 2019-12-11 06:06:50

问题


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

回答1:


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




回答2:


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         
}


来源:https://stackoverflow.com/questions/39072912/getting-phone-type-information-form-telephony-manager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!