Only Email apps to resolve an Intent

后端 未结 14 1559
执念已碎
执念已碎 2020-12-03 06:30

I have a problem .. I want only email activities to resolve intent ACTION.SEND but beside email I get other apps as well (e.g TubeMate) even though I have set the mime type

14条回答
  •  情歌与酒
    2020-12-03 07:13

    Please check : https://developer.android.com/guide/components/intents-common#ComposeEmail

     String[] sendTo = {}; // people who will receive the email
        String subject = "implicit intent | sending email";
        String message = "Hi, this is just a test to check implicit intent.";
        Intent email = new Intent(Intent.ACTION_SENDTO);
        email.setData(Uri.parse("mailto:")); // only email apps should handle this
        email.putExtra(Intent.EXTRA_EMAIL, sendTo);
        email.putExtra(Intent.EXTRA_SUBJECT, subject);// email subject / title
        email.putExtra(Intent.EXTRA_TEXT, message);//message that you want to send
    
        // Create intent to show the chooser dialog
        Intent chooser = Intent.createChooser(email, "Choose an Email client :");
        // Verify the original intent will resolve to at least one activity
        if (chooser.resolveActivity(getPackageManager()) != null) {
            startActivity(chooser);
        }
    

提交回复
热议问题