Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android:如何在双卡手机中获取两个SIM的SIM ID大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在双卡手机中获得两个SIM卡的SIM序列号/ ID.是否有办法获得它们?提前感谢.

解决方法

import java.lang.reflect.Method;

    import android.content.Context;
    import android.telephony.Telephonymanager;

    public final class TelephonyInfo {

    private static TelephonyInfo telephonyInfo;
    private String imeiSIM1;
    private String imeiSIM2;
    private Boolean isSIM1Ready;
    private Boolean isSIM2Ready;

    public String getImeiSIM1() {
        return imeiSIM1;
    }





    /*public static void setImeiSIM1(String imeiSIM1) {
        TelephonyInfo.imeiSIM1 = imeiSIM1;
    }*/

    public String getImeiSIM2() {
        return imeiSIM2;
    }

    /*public static void setImeiSIM2(String imeiSIM2) {
        TelephonyInfo.imeiSIM2 = imeiSIM2;
    }*/

    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 imeiSIM2 != null;
    }

    private TelephonyInfo() {
    }

    public static TelephonyInfo geTinstance(Context context){

        if(telephonyInfo == null) {

            telephonyInfo = new TelephonyInfo();

            Telephonymanager telephonymanager = ((Telephonymanager) context.getSystemservice(Context.TELEPHONY_serviCE));

            telephonyInfo.imeiSIM1 = telephonymanager.getdeviceid();;
            telephonyInfo.imeiSIM2 = null;

            try {
                telephonyInfo.imeiSIM1 = getdeviceidBySlot(context,"getdeviceid@R_235_6@R_675_11241@@",0);
                telephonyInfo.imeiSIM2 = getdeviceidBySlot(context,1);
            } catch (@R_235_6@R_675_11241@@methodNotFoundException E) {
                e.printStackTrace();

                try {
                    telephonyInfo.imeiSIM1 = getdeviceidBySlot(context,"getdeviceid",0);
                    telephonyInfo.imeiSIM2 = getdeviceidBySlot(context,1);
                } catch (@R_235_6@R_675_11241@@methodNotFoundException 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,"getSimState@R_235_6@R_675_11241@@",0);
                telephonyInfo.isSIM2Ready = getSIMStateBySlot(context,1);
            } catch (@R_235_6@R_675_11241@@methodNotFoundException E) {

                e.printStackTrace();

                try {
                    telephonyInfo.isSIM1Ready = getSIMStateBySlot(context,"getSimState",0);
                    telephonyInfo.isSIM2Ready = getSIMStateBySlot(context,1);
                } catch (@R_235_6@R_675_11241@@methodNotFoundException 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 @R_235_6@R_675_11241@@methodNotFoundException {

        String imei = 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){
                imei = ob_phone.toString();

            }
        } catch (Exception E) {
            e.printStackTrace();
            throw new @R_235_6@R_675_11241@@methodNotFoundException(preDictedMethodName);
        }

        return imei;
    }

    private static  Boolean getSIMStateBySlot(Context context,int slotID) throws @R_235_6@R_675_11241@@methodNotFoundException {

        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 getSimState@R_235_6@R_675_11241@@ = telephonyClass.getmethod(preDictedMethodName,parameter);

            Object[] obParameter = new Object[1];
            obParameter[0] = slotID;
            Object ob_phone = getSimState@R_235_6@R_675_11241@@.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 @R_235_6@R_675_11241@@methodNotFoundException(preDictedMethodName);
        }

        return isReady;
    }


    private static class @R_235_6@R_675_11241@@methodNotFoundException extends Exception {

        private static final long serialVersionUID = -996812356902545308L;

        public @R_235_6@R_675_11241@@methodNotFoundException(String info) {
            super(info);
        }
    }
    }



private void isDualSimOrNot(){
    TelephonyInfo telephonyInfo = TelephonyInfo.geTinstance(this);

    String imeiSIM1 = telephonyInfo.getImeiSIM1();
    String imeiSIM2 = telephonyInfo.getImeiSIM2();

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

    Boolean isDualSIM = telephonyInfo.isDualSIM();
    Log.i("Dual = "," IME1 : " + imeiSIM1 + "\n" +
            " IME2 : " + imeiSIM2 + "\n" +
            " IS DUAL SIM : " + isDualSIM + "\n" +
            " IS SIM1 READY : " + isSIM1Ready + "\n" +
            " IS SIM2 READY : " + isSIM2Ready + "\n");
}


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

大佬总结

以上是大佬教程为你收集整理的Android:如何在双卡手机中获取两个SIM的SIM ID全部内容,希望文章能够帮你解决Android:如何在双卡手机中获取两个SIM的SIM ID所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。