我有Dual Sim Android智能手机。我知道Android SDK中不支持Dual Sim设备。我想在默认插槽上访问sim的SIM操作员名称。但是当我运行程序时它会给我一个空字符串。以下是我的代码:
TelephonyManager telemamanger = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
String simOperatorName = telemamanger.getSimOperatorName();
Toast.makeText(AmountActivity.this,simOperatorName,Toast.LENGTH_SHORT).show();
答案 0 :(得分:2)
请改为尝试:
telemamanger.getNetworkOperator()
答案 1 :(得分:0)
// To Get System TELEPHONY service ref
TelephonyManager tManager = (TelephonyManager) getBaseContext()
.getSystemService(Context.TELEPHONY_SERVICE);
// Get Mobile No
String pNumber= tManager.getLine1Number();
// Get carrier name (Network Operator Name)
String networkOperatorName= tManager.getNetworkOperatorName();
答案 2 :(得分:0)
这是获取任何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();
}