Unable to send SMS using SmsManager in Android 13

116 Views Asked by At

I am trying to develop an app that sends SMS. However, the SMS does not get accepted by the network. But if I manually send it, it works.

I have given the following permissions in the manifest:

<uses-permission android:name="android.permission.SEND_SMS" />

And my function to send SMS is:

private void sendSms(String body, String ph) {
    SmsManager smsManager =  getApplicationContext().getSystemService(SmsManager.class).createForSubscriptionId(0);
    ArrayList<String> parts = smsManager.divideMessage(body);
    smsManager.sendMultipartTextMessage(ph, null, parts, null, null);
}

I have also tried createForSubscriptionId(1) and still the same result.

The outgoing SMS is kept in the conversation thread with an error: Not sent, tap to try again. When I tap, it says error 2.

It did send 3 SMS initially and then never sent them again. Can anybody help?

0

There are 0 best solutions below