安卓:检查手机是否是双卡手机、是双卡

2023-09-11 10:38:02 作者:阴谋论

在论坛上大量的调查研究后,现在我知道有没有办法找到IMSI或SIM卡序列号无论是在双卡手机SIM卡(除制造商联系)。现在我改变的问题是,我们能在所有检测到的手机有两个SIM卡?我相信它可以具有一定智能的检测。几种方法我能想到的是:

After a lot of research on forums, now I know that there is no way to find IMSI or SIM serial number for both the SIM cards in a dual SIM phone (except for contacting the manufacturer). Now my changed question is, can we at all detect that the phone has two SIMs? I believe it can be detected with some intelligence. Few ways I can think of are:

拨打USSD code和跟踪日志IMEI号这(我在印度,它的工作,试图与* 139#)会给我的IMEI号码从我拨了USSD的SIM卡code。 (这是presumed,手机遵循Android的指导方针,有两个IMEI号。)

Dialing an USSD code and tracing the logs for IMEI number (I tried this with *139# in India. It worked.) This will give me IMEI number for the SIM from which I dialed the USSD code. (It is presumed that the phone follows android guidelines and has two IMEI numbers.)

存储在SIM序列号和/或IMSI的SIM卡。和检测即使手机没有重新启动(即SIM卡被切换)通过追踪一些日志或部分广播事件处理任何其他IMSI /序列号后。

Storing the SIM serial number and/or IMSI for the SIM. And after detection of any other IMSI/Serial number even if the phone was not rebooted (i.e. the SIM was switched) by tracing some logs or by some broadcast event handling.

通过拨打* 06#,你将能看到这两个IMEI号。通过某种方式,让这两个数字。 (有什么样的屏幕捕捉和图像解析文本。)

By dialing *06# you will get to see both IMEI numbers. By some way, get those two numbers. (Something like screen capturing and image parsing for text.)

如果任何人都可以想一些其他办法,他们是最欢迎的。我真的AP preciate对此任何形式的帮助。此外,如果任何人有任何制造商的API或链接的任何信息与他们联系,请做分享与社区的人。

If anyone can think of some other ways, they are most welcome. I would really appreciate any kind of help regarding this. Also, if anyone has any information about any manufacturers APIs or links to contact them, please do share with the community people.

推荐答案

更新23 March'15:

正式多个SIM API现在可从安卓5.1起

其他可能的选项:

您可以使用 Java反射,以获得这两个IMSI号码。

You can use Java reflection to get both IMSI numbers.

使用这些IMSI号码,你可以检查手机是否是双SIM卡或没有。

Using these IMSI numbers you can check whether the phone is a DUAL SIM or not.

请尝试以下活动:

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TelephonyInfo telephonyInfo = TelephonyInfo.getInstance(this);

        String imsiSIM1 = telephonyInfo.getImsiSIM1();
        String imsiSIM2 = telephonyInfo.getImsiSIM2();

        boolean isSIM1Ready = telephonyInfo.isSIM1Ready();
        boolean isSIM2Ready = telephonyInfo.isSIM2Ready();

        boolean isDualSIM = telephonyInfo.isDualSIM();

        TextView tv = (TextView) findViewById(R.id.tv);
        tv.setText(" IME1 : " + imsiSIM1 + "\n" +
                " IME2 : " + imsiSIM2 + "\n" +
                " IS DUAL SIM : " + isDualSIM + "\n" +
                " IS SIM1 READY : " + isSIM1Ready + "\n" +
                " IS SIM2 READY : " + isSIM2Ready + "\n");
    }
}

这里是 TelephonyInfo.java

And here is TelephonyInfo.java :

import java.lang.reflect.Method;

import android.content.Context;
import android.telephony.TelephonyManager;

public final class TelephonyInfo {

    private static TelephonyInfo telephonyInfo;
    private String imsiSIM1;
    private String imsiSIM2;
    private boolean isSIM1Ready;
    private boolean isSIM2Ready;

    public String getImsiSIM1() {
        return imsiSIM1;
    }

    /*public static void setImsiSIM1(String imsiSIM1) {
        TelephonyInfo.imsiSIM1 = imsiSIM1;
    }*/

    public String getImsiSIM2() {
        return imsiSIM2;
    }

    /*public static void setImsiSIM2(String imsiSIM2) {
        TelephonyInfo.imsiSIM2 = imsiSIM2;
    }*/

    public boolean isSIM1Ready() {
        return isSIM1Ready;
    }

    /*public static void setSIM1Ready(boolean isSIM1Ready) {
        TelephonyInfo.isSIM1Ready = isSIM1Ready;
    }*/

    public boolean isSIM2Ready() {
        return isSIM2Ready;
    }

    /*public static void setSIM2Ready(boolean isSIM2Ready) {
        TelephonyInfo.isSIM2Ready = isSIM2Ready;
    }*/

    public boolean isDualSIM() {
        return imsiSIM2 != null;
    }

    private TelephonyInfo() {
    }

    public static TelephonyInfo getInstance(Context context){

        if(telephonyInfo == null) {

            telephonyInfo = new TelephonyInfo();

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

            telephonyInfo.imsiSIM1 = telephonyManager.getDeviceId();;
            telephonyInfo.imsiSIM2 = null;

            try {
                telephonyInfo.imsiSIM1 = getDeviceIdBySlot(context, "getDeviceIdGemini", 0);
                telephonyInfo.imsiSIM2 = getDeviceIdBySlot(context, "getDeviceIdGemini", 1);
            } catch (GeminiMethodNotFoundException e) {
                e.printStackTrace();

                try {
                    telephonyInfo.imsiSIM1 = getDeviceIdBySlot(context, "getDeviceId", 0);
                    telephonyInfo.imsiSIM2 = getDeviceIdBySlot(context, "getDeviceId", 1);
                } catch (GeminiMethodNotFoundException e1) {
                    //Call here for next manufacturer's predicted method name if you wish
                    e1.printStackTrace();
                }
            }

            telephonyInfo.isSIM1Ready = telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
            telephonyInfo.isSIM2Ready = false;

            try {
                telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimStateGemini", 0);
                telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimStateGemini", 1);
            } catch (GeminiMethodNotFoundException e) {

                e.printStackTrace();

                try {
                    telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimState", 0);
                    telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimState", 1);
                } catch (GeminiMethodNotFoundException e1) {
                    //Call here for next manufacturer's predicted method name if you wish
                    e1.printStackTrace();
                }
            }
        }

        return telephonyInfo;
    }

    private static String getDeviceIdBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {

        String imsi = null;

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

        try{

            Class<?> telephonyClass = Class.forName(telephony.getClass().getName());

            Class<?>[] parameter = new Class[1];
            parameter[0] = int.class;
            Method getSimID = telephonyClass.getMethod(predictedMethodName, parameter);

            Object[] obParameter = new Object[1];
            obParameter[0] = slotID;
            Object ob_phone = getSimID.invoke(telephony, obParameter);

            if(ob_phone != null){
                imsi = ob_phone.toString();

            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeminiMethodNotFoundException(predictedMethodName);
        }

        return imsi;
    }

    private static  boolean getSIMStateBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {

        boolean isReady = false;

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

        try{

            Class<?> telephonyClass = Class.forName(telephony.getClass().getName());

            Class<?>[] parameter = new Class[1];
            parameter[0] = int.class;
            Method getSimStateGemini = telephonyClass.getMethod(predictedMethodName, parameter);

            Object[] obParameter = new Object[1];
            obParameter[0] = slotID;
            Object ob_phone = getSimStateGemini.invoke(telephony, obParameter);

            if(ob_phone != null){
                int simState = Integer.parseInt(ob_phone.toString());
                if(simState == TelephonyManager.SIM_STATE_READY){
                    isReady = true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeminiMethodNotFoundException(predictedMethodName);
        }

        return isReady;
    }


    private static class GeminiMethodNotFoundException extends Exception {

        private static final long serialVersionUID = -996812356902545308L;

        public GeminiMethodNotFoundException(String info) {
            super(info);
        }
    }
}

编辑:

获取的方法,如getDeviceIdGemini其他SIM卡插槽的详细访问都有prediction该方法存在的。

Getting access of methods like "getDeviceIdGemini" for other SIM slot's detail has prediction that method exist.

如果该方法的名称不与一个由设备制造商给出比它不会工作匹配。你必须找到这些设备的相应方法名。

If that method's name doesn't match with one given by device manufacturer than it will not work. You have to find corresponding method name for those devices.

查找方法名称如下:

public static void printTelephonyManagerMethodNamesForThisDevice(Context context) {

    TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    Class<?> telephonyClass;
    try {
        telephonyClass = Class.forName(telephony.getClass().getName());
        Method[] methods = telephonyClass.getMethods();
        for (int idx = 0; idx < methods.length; idx++) {

            System.out.println("\n" + methods[idx] + " declared by " + methods[idx].getDeclaringClass());
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
} 

编辑:的

EDIT :

由于 Seetha 指出,在她的评论:

As Seetha pointed out in her comment :

telephonyInfo.imsiSIM1 = getDeviceIdBySlot(context, "getDeviceIdDs", 0);
telephonyInfo.imsiSIM2 = getDeviceIdBySlot(context, "getDeviceIdDs", 1); 

这是为她工作。她成功地获得两个IMEI号码为SIM卡三星二重奏设备。

It is working for her. She was successful in getting two IMEI numbers for both the SIM in Samsung Duos device.

添加&LT;使用-权限的Andr​​oid:名称=android.permission.READ_PHONE_STATE/&GT;

编辑2:的

EDIT 2 :

用于获取数据的方法对于联想A319等手机由制造(信用马赫Abuthraa )

The method used for retrieving data is for Lenovo A319 and other phones by that manufacture (Credit Maher Abuthraa):

telephonyInfo.imsiSIM1 = getDeviceIdBySlot(context, "getSimSerialNumberGemini", 0); 
telephonyInfo.imsiSIM2 = getDeviceIdBySlot(context, "getSimSerialNumberGemini", 1);