向双SIM卡发送短信

时间:2017-11-30 14:05:33

标签: android sms smsmanager

我有一个脚本短信安卓android。这个脚本工作正常,但我的双SIM卡手机有问题。

我的脚本已成功向SIM卡1发送消息,但未在SIM卡上发送2.任何人都可以在下面修改我的脚本吗?

try {
    System.out.println("MODEL:"+Build.MODEL);
    if (simID == 0) {
        name = Build.MODEL.equals("Philips T939") ? "isms0" : "isms"; //
        // for model : "Philips T939" name = "isms0"
    }
    else if (simID == 1) {
        name = "isms2";
    }
    else {
        throw new Exception("can not get service which for sim '" + simID + "', only 0,1 accepted as values");
    }

    Method declaredMethod = Class.forName("android.os.ServiceManager").getDeclaredMethod("getService", new Class[]{String.class});
    declaredMethod.setAccessible(true);
    Object invoke = declaredMethod.invoke(null, new Object[]{name});

    declaredMethod = Class.forName("com.android.internal.telephony.ISms$Stub").getDeclaredMethod("asInterface", new Class[]{IBinder.class});
    declaredMethod.setAccessible(true);

    invoke = declaredMethod.invoke(null, new Object[]{invoke});
    Log.e("SimUtil", "send msg - " + smsText);

    if (Build.VERSION.SDK_INT < 18) {
        invoke.getClass().getMethod("sendText", new Class[]{String.class, String.class, String.class, PendingIntent.class, PendingIntent.class})
        .invoke(invoke, new Object[]{toNum, centerNum, smsText, sentIntent, deliveryIntent});
    } else if (Build.VERSION.SDK_INT > 18) {
        ArrayList arrayList = new ArrayList();

        for (SubscriptionInfo subscriptionId : SubscriptionManager.from(ctx).getActiveSubscriptionInfoList()) {
            int subscriptionId2 = subscriptionId.getSubscriptionId();
            arrayList.add(Integer.valueOf(subscriptionId2));
            Log.e("SimUtil", "SmsManager - subscriptionId: " + subscriptionId2);
        }
        smsManager.getSmsManagerForSubscriptionId(((Integer) arrayList.get(simID)).intValue()).sendTextMessage(toNum, null, smsText, sentIntent, deliveryIntent);
    } else {
        SmsManager.getDefault().sendTextMessage(toNum, null, smsText, sentIntent, deliveryIntent);
    }
    return true;
} catch (ClassNotFoundException e) {
    Log.e("apipas", "ClassNotFoundException:" + e.getMessage());
    e.printStackTrace();
    Log.e("SimUtil", "error 1");
    return false;
} catch (NoSuchMethodException e) {
    Log.e("apipas", "NoSuchMethodException:" + e.getMessage());
    Log.e("SimUtil", "error 2");
    e.printStackTrace();
    return false;
} catch (InvocationTargetException e) {
    Log.e("apipas", "InvocationTargetException:" + e.getMessage());
    Log.e("SimUtil", "error 3");
    e.printStackTrace();
    return false;
} catch (IllegalAccessException e) {
    Log.e("apipas", "IllegalAccessException:" + e.getMessage());
    Log.e("SimUtil", "error 4");
    e.printStackTrace();
    return false;
} catch (Exception e) {
    Log.e("apipas", "Exception:" + e.getMessage());
    Log.e("SimUtil", "error 5");
    e.printStackTrace();
}
return false;

以下是控制台中的例外情况:

https://i.stack.imgur.com/0xLXp.png

0 个答案:

没有答案