android– 在双卡手机中获取两个simcard *** 作符名称

android– 在双卡手机中获取两个simcard *** 作符名称,第1张

概述我想知道当移动设备是双卡时,两张SIM卡的 *** 作符名称.在单SIM卡中我以编程方式获得了 *** 作符名称但是对于决斗SIM我不能尽管经过这么多的搜索和尝试.如果我在双卡手机中运行我的应用程序,我可以在我的应用程序中获得两个SIM卡运算符名称例如:Idea,Vodafone.编辑:有谁知道如何获取IME

我想知道当移动设备是双卡时,两张SIM卡的 *** 作符名称.在单SIM卡中我以编程方式获得了 *** 作符名称但是对于决斗SIM我不能尽管经过这么多的搜索和尝试.

如果我在双卡手机中运行我的应用程序,我可以在我的应用程序中获得两个SIM卡运算符名称例如:IDea,Vodafone.

编辑:

有谁知道如何获取IMEI的sim *** 作符名称否则我有IMEI号.

码:

public class MainActivity extends Activity {button btnOne, btnTwo;TextVIEw tvInfo;Context context;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_main);    btnOne = (button) findVIEwByID(R.ID.btnOne);    btnTwo = (button) findVIEwByID(R.ID.btnTwo);    tvInfo = (TextVIEw) findVIEwByID(R.ID.tvInfo);    TelephonyInfo telephonyInfo = TelephonyInfo.getInstance(this);    boolean isDualSIM = telephonyInfo.isDualSIM();    boolean isSIM1Ready = telephonyInfo.isSIM1Ready();    boolean isSIM2Ready = telephonyInfo.isSIM2Ready();    TelephonyManager manager = (TelephonyManager) getApplicationContext()            .getSystemService(Context.TELEPHONY_SERVICE);    try {        telephonyInfo.imsiSIM1 = telephonyInfo.getdeviceidBySlot(context,                "getSimserialNumbergemini", 0);        telephonyInfo.imsiSIM2 = telephonyInfo.getdeviceidBySlot(context,                "getSimserialNumbergemini", 1);    } catch (Exception e) {        // Todo auto-generated catch block        e.printstacktrace();    }    String number = manager.getline1Number();    String optname1 = getoutput(getApplicationContext(), "getCarrIErname", 0);    String optname2 = getoutput(getApplicationContext(), "getCarrIErname", 1);    final String carrIErname = manager.getSimOperatorname();    tvInfo.setText(" " + isDualSIM + " " + optname1 + " " + optname2 + " "            + telephonyInfo.imsiSIM1 + " " + telephonyInfo.imsiSIM2 + " "            + number + " " + isSIM1Ready + " " + isSIM2Ready);    btnOne.setonClickListener(new OnClickListener() {        @OverrIDe        public voID onClick(VIEw arg0) {            Intent intent = new Intent(                    Settings.ACTION_ACCESSIBIliTY_SETTINGS);            startActivity(intent);        }    });    btnTwo.setonClickListener(new OnClickListener() {        @OverrIDe        public voID onClick(VIEw arg0) {            if (carrIErname.equalsIgnoreCase("TATA DOCOMO")                    || carrIErname.contains("DOCOMO")) {                startService(new Intent(MainActivity.this, USSD.class));                String ussdCode = "*" + "111" + Uri.encode("#");                startActivity(new Intent(Intent.ACTION_CALL, Uri                        .parse("tel:" + ussdCode)));            } else if (carrIErname.equalsIgnoreCase("!dea")                    || carrIErname.contains("IDea")) {                startService(new Intent(MainActivity.this, USSD.class));                String ussdCode = "*" + "121" + Uri.encode("#");                startActivity(new Intent(Intent.ACTION_CALL, Uri                        .parse("tel:" + ussdCode)));            } else if (carrIErname.equalsIgnoreCase("AIRTEL")                    || carrIErname.contains("airtel")) {                startService(new Intent(MainActivity.this, USSD.class));                String ussdCode = "*" + "123" + Uri.encode("#");                startActivity(new Intent(Intent.ACTION_CALL, Uri                        .parse("tel:" + ussdCode)));            }        }    });}private static String getoutput(Context context, String methodname,        int slotID) {    TelephonyManager telephony = (TelephonyManager) context            .getSystemService(Context.TELEPHONY_SERVICE);    Class<?> telephonyClass;    String reflectionMethod = null;    String output = null;    try {        telephonyClass = Class.forname(telephony.getClass().getname());        for (Method method : telephonyClass.getmethods()) {            String name = method.getname();            if (name.contains(methodname)) {                Class<?>[] params = method.getParameterTypes();                if (params.length == 1 && params[0].getname().equals("int")) {                    reflectionMethod = name;                }            }        }    } catch (ClassNotFoundException e) {        e.printstacktrace();    }    if (reflectionMethod != null) {        try {            output = getopByReflection(telephony, reflectionMethod, slotID,                    false);        } catch (Exception e) {            e.printstacktrace();        }    }    return output;}private static String getopByReflection(TelephonyManager telephony,        String predictedMethodname, int slotID, boolean isPrivate) {    // Log.i("Reflection", "Method: " + predictedMethodname+" "+slotID);    String result = null;    try {        Class<?> telephonyClass = Class.forname(telephony.getClass()                .getname());        Class<?>[] parameter = new Class[1];        parameter[0] = int.class;        Method getSimID;        if (slotID != -1) {            if (isPrivate) {                getSimID = telephonyClass.getDeclaredMethod(                        predictedMethodname, parameter);            } else {                getSimID = telephonyClass.getmethod(predictedMethodname,                        parameter);            }        } else {            if (isPrivate) {                getSimID = telephonyClass                        .getDeclaredMethod(predictedMethodname);            } else {                getSimID = telephonyClass.getmethod(predictedMethodname);            }        }        Object ob_phone;        Object[] obParameter = new Object[1];        obParameter[0] = slotID;        if (getSimID != null) {            if (slotID != -1) {                ob_phone = getSimID.invoke(telephony, obParameter);            } else {                ob_phone = getSimID.invoke(telephony);            }            if (ob_phone != null) {                result = ob_phone.toString();            }        }    } catch (Exception e) {         e.printstacktrace();        // Log.i("Reflection", "Result: " +  e.printstacktrace());         return null;    }    return result;}@OverrIDepublic boolean onCreateOptionsMenu(Menu menu) {    // Inflate the menu; this adds items to the action bar if it is present.    getMenuInflater().inflate(R.menu.main, menu);    return true;}@OverrIDepublic boolean onoptionsItemSelected(MenuItem item) {    // Handle action bar item clicks here. The action bar will    // automatically handle clicks on the Home/Up button, so long    // as you specify a parent activity in AndroIDManifest.xml.    int ID = item.getItemID();    if (ID == R.ID.action_settings) {        return true;    }    return super.onoptionsItemSelected(item);}}

解决方法:

当然,您可以在22版以下的手机中获取dualsim的详细信息.仅在22岁之后才获得官方支持.

private static String getoutput(Context context, String methodname, int slotID) {    TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);    Class<?> telephonyClass;    String reflectionMethod = null;    String output = null;    try {        telephonyClass = Class.forname(telephony.getClass().getname());        for (Method method : telephonyClass.getmethods()) {            String name = method.getname();            if (name.contains(methodname)) {                Class<?>[] params = method.getParameterTypes();                if (params.length == 1 && params[0].getname().equals("int")) {                    reflectionMethod = name;                }            }        }    } catch (ClassNotFoundException e) {        e.printstacktrace();    }    if (reflectionMethod != null) {        try {            output = getopByReflection(telephony, reflectionMethod, slotID, false);        } catch (Exception e) {            e.printstacktrace();        }    }    return output;}private static String getopByReflection(TelephonyManager telephony, String predictedMethodname, int slotID, boolean isPrivate) {    //Log.i("Reflection", "Method: " + predictedMethodname+" "+slotID);    String result = null;    try {        Class<?> telephonyClass = Class.forname(telephony.getClass().getname());        Class<?>[] parameter = new Class[1];        parameter[0] = int.class;        Method getSimID;        if (slotID != -1) {            if (isPrivate) {                getSimID = telephonyClass.getDeclaredMethod(predictedMethodname, parameter);            } else {                getSimID = telephonyClass.getmethod(predictedMethodname, parameter);            }        } else {            if (isPrivate) {                getSimID = telephonyClass.getDeclaredMethod(predictedMethodname);            } else {                getSimID = telephonyClass.getmethod(predictedMethodname);            }        }        Object ob_phone;        Object[] obParameter = new Object[1];        obParameter[0] = slotID;        if (getSimID != null) {            if (slotID != -1) {                ob_phone = getSimID.invoke(telephony, obParameter);            } else {                ob_phone = getSimID.invoke(telephony);            }            if (ob_phone != null) {                result = ob_phone.toString();            }        }    } catch (Exception e) {        //e.printstacktrace();        return null;    }    //Log.i("Reflection", "Result: " + result);    return result;}

使用这两种方法.您必须使用Java反射获取所有SIM卡详细信息.

现在只需使用一行代码即可获得所需的详细信息.

String optname = getoutput(context, "getCarrIErname", 0);

第一个参数是上下文.
第二个参数是您想要访问的方法名称,第三个参数是slotID. “0”表示sim 1.

All the result of this method will be string. Convert them as per your
need.

每个手机都有自己的方法.像micromax一样有像“getCarrIErnameGemni”这样的方法.别担心,我给你的代码将为你处理一切.如果它无法获得结果,它将返回null.快乐的编码!

总结

以上是内存溢出为你收集整理的android – 在双卡手机中获取两个simcard *** 作符名称全部内容,希望文章能够帮你解决android – 在双卡手机中获取两个simcard *** 作符名称所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存