10

I follow this code:

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setType("vnd.android-dir/mms-sms");
    startActivity(intent);

It work up to android 5.1, but doesn't work android 6.0, because android.content.ActivityNotFoundException: No Activity found to handle Intent. So, how to open sms app via implicit intent?

EDIT:

  1. You read my post? I need open app, not send message.

  2. I check this post, but it doesn't work!

Community
  • 1
  • 1
D. Wayne
  • 173
  • 1
  • 1
  • 8

10 Answers10

20

You can try this, it work for me:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_MESSAGING);
startActivity(intent);
Sergey Molyak
  • 310
  • 3
  • 14
8

Use this:

public void composeSmsMessage(String message, String phoneNumber) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setData(Uri.parse("smsto:"+phoneNumber)); // This ensures only SMS apps respond
    intent.putExtra("sms_body", message);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

Official Docmentation

Prerak Sola
  • 9,517
  • 7
  • 36
  • 67
3

Try this:-

try {

     Intent intent = new Intent(Intent.ACTION_VIEW);     
     intent.putExtra("sms_body", message);    
     intent.setData(Uri.parse("sms:"));
     startActivity(intent);
} catch (android.content.ActivityNotFoundException anfe) {
    Log.d("Error" , "Error");
}
Ankesh kumar Jaisansaria
  • 1,563
  • 4
  • 26
  • 44
  • Its Working fine – jojo Dec 06 '17 at 11:31
  • @Ankesh kumar Jaisansaria Does it matter what the String is after "...setData(Uri.parse"String:")? I see many examples using "sms:" and many others using "smsto:" – AJW Apr 20 '20 at 05:59
3

try this:

Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", "12125551212");
smsIntent.putExtra("sms_body","Body of Message");
startActivity(smsIntent);
Manish
  • 353
  • 2
  • 18
3

Below code Perfectly worked for me, Hope it will help other

This code also works if you want to return to app back

Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse("smsto:" + phoneNumber)); // This ensures only SMS apps respond
        intent.putExtra("sms_body", "Hey downaload Whozhere app");
        startActivity(intent);
Sukhbir
  • 1,410
  • 14
  • 33
2

official doc https://developer.android.com/guide/components/intents-common#SendMessage

public void composeMmsMessage(String message, Uri attachment) {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setType(HTTP.PLAIN_TEXT_TYPE);
    intent.putExtra("sms_body", message);
    intent.putExtra(Intent.EXTRA_STREAM, attachment);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}
0

You can use this too

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:" + Uri.encode(phoneNumber)));
startActivity(intent);
Krishna
  • 343
  • 5
  • 22
0

you can used deep linking using intent filter in manifest file

Bipin Bharti
  • 1,034
  • 2
  • 14
  • 27
0
Intent intent = new Intent(Intent.ACTION_SENDTO);

intent.setData(Uri.parse("smsto:" + Uri.encode(phoneNumber))); startActivity(intent);

  • Hello, please add a comment to explain your answer (and why we should use your instead of already accepted one). Please also add 4 spaces at beginning of each line of code to have it formatted well ! – NatNgs Jan 16 '18 at 16:16
0
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);

it's working

NOGO
  • 1
  • 1
    Can you explain how does the same code works for you. Some details other that just _it's working_ will be useful. –  Dec 09 '19 at 17:18