作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有双卡 Android 智能手机。我知道 android SDK 不支持双卡双待设备。我想在默认插槽上访问 sim 的 sim 运营商名称。但是当我运行程序时,它给了我一个空字符串。以下是我的代码:
TelephonyManager telemamanger = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
String simOperatorName = telemamanger.getSimOperatorName();
Toast.makeText(AmountActivity.this,simOperatorName,Toast.LENGTH_SHORT).show();
最佳答案
这是获取任何 Android 设备的 SIM 卡名称的完整代码。
//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();
}
关于java - 如何从 Dual Sim Android 设备获取 Sim 运营商名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35686419/
我是一名优秀的程序员,十分优秀!