Android:如何在双卡手机中获取两个SIM的SIM ID

Android:如何在双卡手机中获取两个SIM的SIM ID,第1张

概述我想在双卡手机中获得两个SIM卡的SIM序列号/ ID.是否有办法获得它们?提前感谢. import java.lang.reflect.Method; import android.content.Context; import android.telephony.TelephonyManager; public final class TelephonyInfo { 我想在双卡手机中获得两个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.get@R_419_4306@();;            telephonyInfo.imeiSIM2 = null;            try {                telephonyInfo.imeiSIM1 = get@R_419_4306@BySlot(context,"get@R_419_4306@gemini",0);                telephonyInfo.imeiSIM2 = get@R_419_4306@BySlot(context,1);            } catch (geminiMethodNotFoundException e) {                e.printstacktrace();                try {                    telephonyInfo.imeiSIM1 = get@R_419_4306@BySlot(context,"get@R_419_4306@",0);                    telephonyInfo.imeiSIM2 = get@R_419_4306@BySlot(context,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,1);            } catch (geminiMethodNotFoundException e) {                e.printstacktrace();                try {                    telephonyInfo.isSIM1Ready = getSimstateBySlot(context,"getSimstate",0);                    telephonyInfo.isSIM2Ready = getSimstateBySlot(context,1);                } catch (geminiMethodNotFoundException e1) {                    //Call here for next manufacturer's predicted method name if you wish                    e1.printstacktrace();                }            }        }        return telephonyInfo;    }    private static String get@R_419_4306@BySlot(Context context,String predictedMethodname,int slotID) throws geminiMethodNotFoundException {        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 geminiMethodNotFoundException(predictedMethodname);        }        return imei;    }    private static  boolean getSimstateBySlot(Context context,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);        }    }    }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所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1127540.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存