【发布时间】: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;
}
【问题讨论】: