Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android手机中获取第二张Sim卡的IMSI号_Android - Fatal编程技术网

如何在Android手机中获取第二张Sim卡的IMSI号

如何在Android手机中获取第二张Sim卡的IMSI号,android,Android,我使用的是TelephonyManager,我可以获得SIM1的SubscriberID(IMSI),但无法获得SIM2的相同ID。然而,我能够为两个SIM卡插槽获取IMEI no,但仍然无法为第二个SIM卡获取IMSI。有没有办法获取此信息?您可以从电话管理器使用getDeviceId方法 记住,这是一种获取订户ID的黑客方法,因此可能无法在所有设备上运行 将在Android 5.1.1及以上版本上运行,并且需要Android.permission.READ_PHONE_STATE权限 (请记

我使用的是TelephonyManager,我可以获得SIM1的SubscriberID(IMSI),但无法获得SIM2的相同ID。然而,我能够为两个SIM卡插槽获取IMEI no,但仍然无法为第二个SIM卡获取IMSI。有没有办法获取此信息?

您可以从电话管理器使用getDeviceId方法


记住,这是一种获取订户ID的黑客方法,因此可能无法在所有设备上运行

将在Android 5.1.1及以上版本上运行,并且需要Android.permission.READ_PHONE_STATE
权限

(请记住向用户询问上述棉花糖中的android.permission.READ_PHONE_STATE权限。) android版本,因为它被标记为危险)


这是安卓7.0的IMEI而不是IMSIAs。有一个本机方法可以做到这一点:
tm.createForSubscriptionId(sm.getActiveSubscriptionInfo-ForSimslotIndex(1.getSubscriptionId()).getSubscriptionId()
public String getSim1IMSI() {
    String imsi = null;
    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    try {
        Method getSubId = TelephonyManager.class.getMethod("getSubscriberId", int.class);
        SubscriptionManager sm = (SubscriptionManager) getSystemService(TELEPHONY_SUBSCRIPTION_SERVICE);
        imsi = (String) getSubId.invoke(tm, sm.getActiveSubscriptionInfoForSimSlotIndex(0).getSubscriptionId()); // Sim slot 1 IMSI
        return imsi;
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
    return imsi;
}


public String getSim2IMSI() {
    String imsi = null;
    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    try {
        Method getSubId = TelephonyManager.class.getMethod("getSubscriberId", int.class);
        SubscriptionManager sm = (SubscriptionManager) getSystemService(TELEPHONY_SUBSCRIPTION_SERVICE);
        imsi = (String) getSubId.invoke(tm, sm.getActiveSubscriptionInfoForSimSlotIndex(1).getSubscriptionId()); // Sim slot 2 IMSI
        return imsi;
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
    return imsi;
}