Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting an SMS message intent is no longer working for new Droid RAZR ICS operating system

starting an SMS message intent (compose pre-populated text) is no longer working for new Droid RAZR ICS operating system. Are there other ways to accomplish this task?

I have tried both:

  Intent sendIntent = new Intent(Intent.ACTION_VIEW); 
    sendIntent.putExtra("sms_body", smsBody); 
    sendIntent.setType("vnd.android-dir/mms-sms"); 
    startActivity(sendIntent);

Also tried,

Uri.parse(uri);

The body of the text message is not pre-populating meanwhile it behaves correctly for all other devices and operating systems to my knowledge.

like image 895
gauglerb Avatar asked Jul 06 '12 17:07

gauglerb


2 Answers

I ran into this problem as well, and eventually concluded the "sms_body" string is no longer applicable in Android 4; instead the more logical Intent.EXTRA_TEXT key is used.

    String text = "Hello world";
    i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse("sms:"));
    // i.setType("vnd.android-dir/mms-sms");
    i.putExtra(Intent.EXTRA_TEXT, text);
    i.putExtra("sms_body", text);
    startActivity(i);

This code appears to work in both Android 2.x and Android 4.0, although I can find no documentation supporting it. I chose to go with the "sms:" URI rather than using a mime-type, since the mime type appears to be unfortunately nonstandardized.

like image 20
Dorje Avatar answered Sep 19 '22 16:09

Dorje


Use ACTION_SENDTO with a smsto: Uri for the phone number that you want to send the message to.

The MIME type you are using is undocumented and therefore subject to change, at will, by the core Android team or device manufacturers.

like image 184
CommonsWare Avatar answered Sep 18 '22 16:09

CommonsWare