问题
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