0

I have tried with code mentioned on this link How to send a SMS using SMSmanager in Dual SIM mobile? I used name for simID is "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());
    }

but this code is giving following Exception on line starts with ===> in else block: SecurityException: Binder invocation to an incorrect interface

Any Idea about it ?

Community
  • 1
  • 1
Happy Mittal
  • 109
  • 7
  • Add your error logs correctly. As well as your code. NO We don't like to imagine your code's way through. We are not John Lennon. – O_o Sep 28 '16 at 17:13
  • Use break-point and step-by-step debugging for verifying that the returned service is really of class `com.android.internal.telephony.ISms$Stub`. – Robert Sep 28 '16 at 17:34
  • updated code in question. Code is working fine for simID == 0 and name = "isms". It is giving exception in case of simID == 1 and "isms_msim". I want to implement Dual SIM feauture for API level 19 which is not supported by android (acc. to the documentation). – Happy Mittal Sep 29 '16 at 08:45

1 Answers1

0

I got the solution by myself after spending some time. call the API from https://github.com/gp-b2g/frameworks_base/blob/master/telephony/java/android/telephony/MSimSmsManager.java and https://github.com/gp-b2g/frameworks_base/blob/master/telephony/java/android/telephony/MSimTelephonyManager.java file by java reflection to get subscription info and to send SMS.

Happy Mittal
  • 109
  • 7