-1

I am trying to send a SMS from my application that already set as default SMS application. I have tried to send using SmsManager, but it does not work.
Here is what I have tried:

SmsManager smsMan = SmsManager.getDefault();
smsMan.sendTextMessage(Name, null, body, null, null);

This approach works when my application was not set as default app, but it didn't when my app is the default one. Is there any other approach to send a SMS from inside the default SMS application?

Bullockta Bodax
  • 549
  • 5
  • 13
  • http://stackoverflow.com/questions/19560323/send-sms-message-using-non-default-sms-app-on-android-4-4 – Nirav Ranpara Mar 17 '16 at 04:39
  • When you're testing as the default SMS app, are you sure your message isn't exceeding the character limit for a single-part message? – Mike M. Mar 17 '16 at 04:41
  • It should use the set default SMS app. My question is, how are you trying to determine that it is not using your own SMS app to send the message. – Aizen Mar 17 '16 at 04:49
  • @MikeM. no, I just trying to send a single piece of word. – Bullockta Bodax Mar 17 '16 at 05:47
  • How are you determining that it's not working? Is the recipient just not receiving the message? Is the outgoing message just not showing in another SMS app? Is it throwing an Exception? Also, are you sure the address is correct? That is, the first argument in the method call, `Name`. – Mike M. Mar 17 '16 at 05:50
  • @MikeM.as you already mention, the recipient did not received the message. i have not check the address. btw, does my aprroach already correct? – Bullockta Bodax Mar 17 '16 at 05:57
  • Yeah, sending text messages is the same for both default and non-default apps, so that should work for ya, provided everything is correct; i.e., the address, the permissions, etc. – Mike M. Mar 17 '16 at 06:05

1 Answers1

0

Try the below code to send message

String number = "12346556";  // The number on which you want to send SMS  
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null))); 
raasesh
  • 161
  • 11
  • The OP is asking about their app acting as the default SMS app, for which they need to use `SmsManager`. Your code is not appropriate to that requirement, as it is meant to open another app to handle the message. Furthermore, `ACTION_VIEW` isn't really what you want in that case, anyway. – Mike M. Mar 17 '16 at 05:21
  • Else try SEND_TO for your purpose... 'String phoneNumber = "9999999999"; String smsBody = "This is an SMS!"; // Add the phone number in the data Uri uri = Uri.parse("smsto:" + phoneNumber); // Create intent with the action and data Intent smsIntent = new Intent(Intent.ACTION_SENDTO, uri); // smsIntent.setData(uri); // We just set the data in the constructor above // Set the message smsIntent.putExtra("sms_body", smsBody); startActivity(smsIntent);' – raasesh Mar 17 '16 at 05:32
  • Again, this really isn't pertinent to the OP's situation. – Mike M. Mar 17 '16 at 05:35
  • @raasesh I've tried that approach, it didn't work either – Bullockta Bodax Mar 17 '16 at 05:48