我从sdk级别android.os.Build.VERSION_CODES.LOLLIPOP_MR1知道我们将subscriptionInfoList作为subscriptionManager.getActiveSubscriptionInfoList();
并以此识别所有支持的SIM卡信息。

我需要在android较低版本中获得同样的效果。有人可以帮助我吗?

最佳答案

幸运的是,有几种本机解决方案。

对于API> = 17:

TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

// Get information about all radio modules on device board
// and check what you need by calling #getCellIdentity.

final List<CellInfo> allCellInfo = manager.getAllCellInfo();
for (CellInfo cellInfo : allCellInfo) {
    if (cellInfo instanceof CellInfoGsm) {
        CellIdentityGsm cellIdentity = ((CellInfoGsm) cellInfo).getCellIdentity();
        //TODO Use cellIdentity to check MCC/MNC code, for instance.
    } else if (cellInfo instanceof CellInfoWcdma) {
        CellIdentityWcdma cellIdentity = ((CellInfoWcdma) cellInfo).getCellIdentity();
    } else if (cellInfo instanceof CellInfoLte) {
        CellIdentityLte cellIdentity = ((CellInfoLte) cellInfo).getCellIdentity();
    } else if (cellInfo instanceof CellInfoCdma) {
        CellIdentityCdma cellIdentity = ((CellInfoCdma) cellInfo).getCellIdentity();
    }
}


在AndroidManifest中添加权限:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>


要获取网络运营商,您可以检查mcc和mnc代码:


https://en.wikipedia.org/wiki/Mobile_country_code(一般信息)。
https://clients.txtnation.com/hc/en-us/articles/218719768-MCCMNC-mobile-country-code-and-mobile-network-code-list-(相当完整的最新操作员列表)。


对于最新的设备,您可以使用最新的API。

对于API> = 22:

final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
final List<SubscriptionInfo> activeSubscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
for (SubscriptionInfo subscriptionInfo : activeSubscriptionInfoList) {
    final CharSequence carrierName = subscriptionInfo.getCarrierName();
    final CharSequence displayName = subscriptionInfo.getDisplayName();
    final int mcc = subscriptionInfo.getMcc();
    final int mnc = subscriptionInfo.getMnc();
    final String subscriptionInfoNumber = subscriptionInfo.getNumber();
}


对于API> = 23。要仅检查电话是否为双/三/多SIM卡:

TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if (manager.getPhoneCount() == 2) {
    // Dual sim
}

关于android - 如何在小于android.os.Build.VERSION_CODES.LOLLIPOP_MR1的sdk级别识别双SIM卡运营商名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40373191/

10-10 03:57