获取双卡Android手机的操作员详细信息

时间:2014-03-04 11:14:57

标签: android imei dual-sim

我正在开发一个应用程序,我需要用户SIM卡的详细信息 他的电话号码,imei号码和运营商。到目前为止,我已经实现了他的IMEI号码引用this answer,是他的设备单SIM或双SIM卡。 如何获得两个连接的SIM卡号和操作员名称。

4 个答案:

答案 0 :(得分:2)

试试这个,对我有用:

TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String carrierName = manager.getNetworkOperatorName();

答案 1 :(得分:2)

幸运的是,有几种原生解决方案。希望这会对某人有所帮助。

对于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&gt; = 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&gt; = 23。要检查手机是双/三/多SIM卡:

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

答案 2 :(得分:0)

试试这里:

private List<String> getNetworkOperator(final Context context) {
    // Get System TELEPHONY service reference
    List<String> carrierNames = new ArrayList<>();
    try {
        final String permission = Manifest.permission.READ_PHONE_STATE;
        if ( (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) && (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED) ){
            final List<SubscriptionInfo> subscriptionInfos = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
            for (int i = 0; i < subscriptionInfos.size(); i++) {
                carrierNames.add(subscriptionInfos.get(i).getCarrierName().toString());
            }

        } else {
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            // Get carrier name (Network Operator Name)
            carrierNames.add(telephonyManager.getNetworkOperatorName());

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return carrierNames;
}

答案 3 :(得分:0)

        // Use this code, it will provide all the info realated both sim card 

        Required Permission:
        <uses-permission android:name="android.permission.READ_PHONE_STATE"/> 

            if (getSimInfo(context).get(0) != null) {  // SIM 1
                               getSimInfo(context).get(0).getMcc()); 
                               getSimInfo(context).get(0).getMnc());
                            } else {
                               Log.d("Sim card", "Sim card not available");
                            }
                            if (getSimInfo(context).get(1) != null) { // SIM 2
                                getSimInfo(context).get(1).getMcc());
                                getSimInfo(context).get(1).getMnc());
                            } else {
                               Log.d("Sim card", "Sim card not available");
                            }
                            if (getNetworkOperator(context).get(0) != null) { // SIM 1
     (String)getSimInfo(context).get(0).getCarrierName());
                            } else {
                               Log.d("Sim card", "Sim card not available");
                            }
                            if (getNetworkOperator(context).get(1) != null) {// SIM 2 
 (String)getSimInfo(context).get(1).getCarrierName());
                            } else {
                              Log.d("Sim card", "Sim card not available");
                            }

        // getSimInfo
        public List<SubscriptionInfo> getSimInfo(Context context) {
                SubscriptionManager subManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
                List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
                subscriptionInfoList = subManager.getActiveSubscriptionInfoList();
                Log.d("LIST LIST", subscriptionInfoList.toString());
                if (subscriptionInfoList == null) {
                    Toast.makeText(context, "address not found", Toast.LENGTH_SHORT).show();
                }
                return subscriptionInfoList;
            }

            // getNetworkOperator 
            public List<String> getNetworkOperator(final Context context) {
                // Get System TELEPHONY service reference
                List<String> carrierNames = new ArrayList<>();
                try {
                    final String permission = android.Manifest.permission.READ_PHONE_STATE;
                    if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) && (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED)) {
                        final List<SubscriptionInfo> subscriptionInfos = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
                        for (int i = 0; i < subscriptionInfos.size(); i++) {
                            carrierNames.add(subscriptionInfos.get(i).getCarrierName().toString());
                        }

                    } else {
                        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                        // Get carrier name (Network Operator Name)
                        carrierNames.add(telephonyManager.getNetworkOperatorName());
            enter code here
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return carrierNames;
            }