Sami
Sami

Reputation: 3976

send sms in pdu mode using android

I am developing an application which needs to send sms in pdu mode.

I am using this code but it gives NoSuchElementException on first line.

try {
        Method m2 = sms.getClass().getDeclaredMethod("sendRawPdu", pdu.getClass(), pdu.getClass(), piSent.getClass(), piDelivered.getClass());
        m2.setAccessible(true);
        SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(null, "", "Test", false);


        Object[] arrayOfObject2 = new Object[5];
        arrayOfObject2[0] = pdus.encodedScAddress;
        arrayOfObject2[1] = pdus.encodedMessage;
        arrayOfObject2[2] = piSent;
        arrayOfObject2[3] = piDelivered;
        arrayOfObject2[4] = null;

        try {
            m2.invoke(sms, arrayOfObject2);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }

Any help will be appreciated.

Upvotes: 0

Views: 897

Answers (1)

moonzai
moonzai

Reputation: 439

I tried it on Lollipop, but there is no method related to sendRawPdu

Do a little more thing just print the list of methods available to check if there is any method related to sendRawPdu

Method[] methods = sms.getClass().getDeclaredMethods();
boolean methodAvailable = false;
for(Method m : methods) {
    Log.d("SmsManager", m.toString());
    if(m.toString().contains("sendRawPdu")) {
        methodAvailable = true;
    }
}

now you have methodAvailable, if it is true you can send Raw PDU, if not then you can't. sendRawPdu was available before JellyBeans. Try to run this on Pre JellyBeans devices.

Upvotes: 1

Related Questions