0

電話がデュアルSIMの場合はネットワークオペレーター名を取得するか、隣接するネットワークオペレーター名のリスト全体を取得する必要があります。私が見つけたものをグーグルで調べたとき、ネットワークオペレーター名はこれです

TelephonyManager tManager = (TelephonyManager) getBaseContext()
      .getSystemService(Context.TELEPHONY_SERVICE);

// Get carrier name (Network Operator Name) 
String carrierName = tManager.getNetworkOperatorName();

しかし、これは私にはうまくいきません。どうすればこれを達成できますか。そうでない場合は、いくつかの解決策を提案してください。ありがとう

4

1 に答える 1

0

幸いなことに、いくつかのネイティブ ソリューションがあります。

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 コードを確認できます。

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
}
于 2016-11-05T14:55:49.317 に答える