【问题标题】:How to read IMEI from Dual SIM Phone如何从双卡手机读取 IMEI
【发布时间】:2014-12-01 07:13:43
【问题描述】:

我正在使用 Xamarin (C#) 编写一个 Android 应用程序,该应用程序需要从双 SIM 卡手机中的两张 SIM 卡中获取 IMEI 和漫游状态。我找到了一些Java代码来做到这一点。但我不知道如何将 Java 反射翻译成 C#(即使我使用 Java-C# 翻译器来做)。这是链接:Android : Check whether the phone is dual SIM

有人可以帮我吗?

这里是文章中需要翻译成C#的代码sn-p

private static String getDeviceIdBySlot(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;
} 

【问题讨论】:

    标签: java c# android xamarin


    【解决方案1】:

    首先在你的 Manifest 中添加权限为

    &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;

    这将返回 IMEI android.telephony.TelephonyManager.getDeviceId().

    【讨论】:

      猜你喜欢
      • 2012-08-06
      • 1970-01-01
      • 2014-05-05
      • 1970-01-01
      • 1970-01-01
      • 2012-05-27
      • 2016-12-11
      • 2019-10-29
      • 2014-11-03
      相关资源
      最近更新 更多