Search code examples
androidsmsandroid-permissions

Why is my app not able to send SMS even with requisite permissions?


My app is trying to send a sms to another number. I have the requisite permission(SEND_SMS) granted by the user. The message however does not get sent.The default messaging app display the message with a "failure to send/Resend" prompt. What is the reason behind this and how do I fix this? My code is pretty straightforward-

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneno, null, txt, null, null);

Note- My app operates well below the sms frequency limit Edit : It works fine when run from an activity but fails when run from a service. What's the reasoning behind this ?


Solution

  • The problem seemed to be because of where the code was getting called from . I had a service (running on a seperate thread) spawn a new thread to send out the SMSs , for some reason this seemed to lead to problems. After I removed all that unnecessary complexity and have the sms sent directly from the service it works fine.