[英]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.