gpt4 book ai didi

java - 如何从 Dual Sim Android 设备获取 Sim 运营商名称?

转载 作者:可可西里 更新时间:2023-11-01 11:42:35 24 4
gpt4 key购买 nike

我有双卡 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com