Only Email apps to resolve an Intent

2019-01-14 15:02发布

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 as 'message/rfc822' ... Any idea how can I get Email applications to resolve it ..

9条回答
淡お忘
2楼-- · 2019-01-14 15:39

u can also use:

//writes messages only to email clients
public void setWriteEmailButton() {
    btnWriteMail.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Intent i = new Intent(Intent.ACTION_SENDTO);
            i.setData(Uri.parse("mailto:"));
            i.putExtra(Intent.EXTRA_EMAIL  , new String[]{mConsultantInfos.getConsultantEMail()});
            i.putExtra(Intent.EXTRA_SUBJECT, mContext.getString(R.string.txtSubjectConsultantMail));
            i.putExtra(Intent.EXTRA_TEXT   , "");
            try {
                startActivity(Intent.createChooser(i, mContext.getString(R.string.txtWriteMailDialogTitle)));
            } catch (android.content.ActivityNotFoundException ex) {
                UI.showShortToastMessage(mContext, R.string.msgNoMailClientsInstalled);
            }
        }
    });
}

have fun (combination of both ;))

查看更多
来,给爷笑一个
3楼-- · 2019-01-14 15:40

When I use intent android.content.Intent.ACTION_SENDTO doesn't work for me because it shows many apps, some apps are not email clients. I found this way and it works perfectly for me.

Intent testIntent = new Intent(Intent.ACTION_VIEW);  
Uri data = Uri.parse("mailto:?subject=" + "blah blah subject" + "&body=" + "blah blah body" + "&to=" + "sendme@me.com");  
testIntent.setData(data);  
startActivity(testIntent);
查看更多
祖国的老花朵
4楼-- · 2019-01-14 15:42

Try this

String subject = "Feedback";
            String bodyText = "Enter text email";
            String mailto = "mailto:bob@example.org" +
                    "?cc=" + "" +
                    "&subject=" + Uri.encode(subject) +
                    "&body=" + Uri.encode(bodyText);

            Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
            emailIntent.setData(Uri.parse(mailto));

            try {
                startActivity(emailIntent);
            } catch (ActivityNotFoundException e) {
                //TODO: Handle case where no email app is available
            }

Credit: https://medium.com/@cketti/android-sending-email-using-intents-3da63662c58f

查看更多
够拽才男人
5楼-- · 2019-01-14 15:44

In Android, there's no such thing as an email activity. There's also no intent filter that can be created to include only email applications. Each application (or activity) can define its own intent filters.

So when using intent ACTION_SEND, you'll have to rely on the users intelligence to pickhis favorite email app from the chooser (and not TubeMate).

查看更多
对你真心纯属浪费
6楼-- · 2019-01-14 15:45
 private void sendEmail(Connect connect) {
    Intent email = new Intent(Intent.ACTION_SENDTO);
    email.setData(Uri.parse("mailto:"));
    email.putExtra(Intent.EXTRA_EMAIL, new String[]{connect.getEmail()});
    email.putExtra(Intent.EXTRA_SUBJECT, "");
    email.putExtra(Intent.EXTRA_TEXT, "");
    try {
        startActivity(Intent.createChooser(email, getString(R.string.choose_email_client)));
    } catch (ActivityNotFoundException activityNotFoundException) {
        UIUtils.showShortSnackBar(fragmentConnectLayout, getString(R.string.no_email_client));
    }
}

Refer https://developer.android.com/guide/components/intents-common.html#Email

查看更多
▲ chillily
7楼-- · 2019-01-14 15:47
String recepientEmail = ""; // either set to destination email or leave empty
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:" + recepientEmail));
startActivity(intent);

The point is to use ACTION_SENDTO as action and mailto: as data. If you want to let the user specify the destination email, use just mailto:; if you specify email yourself, use mailto:name@domain.com

Suggested method filters all the application, that can send email(such as default email app or gmail)

查看更多
登录 后发表回答