Android: send SMS through intent with body and go back.

I am trying to send an SMS via intent, I want to add a body to the message. After clicking send I want to return to the application. I added additional ones like sms_body and exit_on_sent . But when I use them, both SMSs appear without a body. If I do not use exit_on_sent , everything works fine.

  Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.setData(Uri.parse("smsto:" + phoneNumber)); sendIntent.putExtra("sms_body", "some text"); sendIntent.putExtra("exit_on_sent", true); context.startActivity(sendIntent); 
+8
android android-intent
source share
1 answer

You can try using

 startActivityForResult(sendIntent, SOME_REQUEST_CODE) 

but in my experience it doesn't work most of the time. I would recommend using SmsManager instead.

 SmsManager smsMgr = SmsManager.getDefault(); if(smsMgr != null){ PendingIntent sentIntent = PendingIntent.getBroadcast( getActivity().getApplicationContext(), 0, new Intent(MY_ACTION_INTENT_SENT), 0); smsMgr.sendTextMessage(phone, null, message, sentIntent, null); } 

Depending on your application, you can perform the remaining processing when MY_ACTION_INTENT is sent (indicating that the message is indeed sent) or immediately after sendTextMessage (...) returns.

From API level 19 you can find interesting features http://developer.android.com/reference/android/provider/Telephony.html

Hope this helps.

+1
source share

All Articles