[英]How to send a SMS using java reflection in Dual SIM mobile Moto E ( android version 4.4.4)?
我尝试使用此链接上提到的代码。 如何在Dual SIM手机中使用SMSmanager发送短信? 我使用的simID名称是“ isms_msim”。
try {
if (simID == 0) {
name = "isms";
} else if (simID == 1) {
name = "isms_msim";
} else {
throw new Exception("can not get service which for sim '" + simID + "', only 0,1 accepted as values");
}
Method method = Class.forName("android.os.ServiceManager").getDeclaredMethod("getService", String.class);
method.setAccessible(true);
Object param = method.invoke(null, name);
method = Class.forName("com.android.internal.telephony.ISms$Stub").getDeclaredMethod("asInterface", IBinder.class);
method.setAccessible(true);
Object stubObj = method.invoke(null, param);
if (Build.VERSION.SDK_INT < 18) {
method = stubObj.getClass().getMethod("sendMultipartText", String.class, String.class, List.class, List.class, List.class);
method.invoke(stubObj, toNum, centerNum, smsTextlist, sentIntentList, deliveryIntentList);
} else {
method = stubObj.getClass().getMethod("sendMultipartText", String.class, String.class, String.class, List.class, List.class, List.class);
===> method.invoke(stubObj, ctx.getPackageName(), toNum, centerNum, smsTextlist, sentIntentList, deliveryIntentList);
}
return true;
} catch (ClassNotFoundException e) {
Logger.Log(TAG, Logger.LogLevel.ERROR, "Error while sending multiple sms, stack trace: " + e.getStackTrace());
} catch (NoSuchMethodException e) {
Logger.Log(TAG, Logger.LogLevel.ERROR, "Error while sending multiple sms, stack trace: " + e.getStackTrace());
} catch (InvocationTargetException e) {
Logger.Log(TAG, Logger.LogLevel.ERROR, "Error while sending multiple sms, stack trace: " + e.getStackTrace());
} catch (IllegalAccessException e) {
Logger.Log(TAG, Logger.LogLevel.ERROR, "Error while sending multiple sms, stack trace: " + e.getStackTrace());
} catch (Exception e) {
Logger.Log(TAG, Logger.LogLevel.ERROR, "Error while sending multiple sms, stack trace: " + e.getStackTrace());
}
但是此代码在else块中以===>开头的行上给出以下Exception:SecurityException:活页夹调用到错误的接口
有任何想法吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.