Search code examples
androidandroid-intentsmsandroid-5.0-lollipop

Opening sms intent in Android lollipop


I'm using the following code to open an intent.

The problem is that the sms_body is no shown in the intent

String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context);
intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + Uri.encode(numbers.toString())));
intent.putExtra("sms_body", text);
if (defaultSmsPackageName != null) 
{
    intent.setPackage(defaultSmsPackageName);
}

Any idea on how I can transfer the sms_body in lollipop.


Solution

  • Use this code:

     String yournumber="123456";
     Intent sendIntent = new Intent(Intent.ACTION_VIEW);
            sendIntent.setData(Uri.parse("sms:"+yournumber));
            sendIntent.putExtra("sms_body", "My first sms");
            startActivity(sendIntent);