Explicit intent for Android default email client

前端 未结 1 1315
面向向阳花
面向向阳花 2021-01-27 01:52

I need to directly start the compose activity of the default Android email client. I also need to add more than one attachment to the email. Where I can find the component name

相关标签:
1条回答
  • 2021-01-27 02:26

    Ok, checking the source code of the Android Email system app I finally found it.

    String subject = ...
    String text = ...
    ArrayList<Uri> attachments = ...
    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
    intent.setClassName("com.android.email", "com.android.email.activity.MessageCompose");
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException anfe) {
        anfe.printStackTrace();
    }
    

    This seems to work from Android 4.0 to Android 4.3. In Android 4.4 (KitKat) the name of the Activity has changed in com.android.email.activity.ComposeActivityEmail, but I haven't tested it.

    0 讨论(0)
提交回复
热议问题