我想知道如何从TelephonyManager
访问手机类型信息[无论是GSM还是CDMA]。我可以使用哪个功能:
我的代码是:
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();
答案 0 :(得分:2)
您可以使用Telephony Manager
实现此目的您必须在AndroidManifest文件中声明以下权限..
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
拥有TelephonyMnager的对象
TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
获取电话类型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;
}
有关详情,请参阅此Telephony Manager
答案 1 :(得分:0)
试试这可能会对你有所帮助
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
}