ACTION_SEND force sending with email

2019-03-27 15:57发布

every time i create an action for sending an email from my app, it prompts to many options including a QR client...

Is there a way to force sending via email clients only?

Code for sending the email

String rec[] = { owner.email };
i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_EMAIL, rec);
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "RE: " + desc);
i.putExtra(android.content.Intent.EXTRA_TEXT,
        "\n\n\nSent from Mojo for Android");
startActivity(i);

Screenshot for what happens when I launch this screenshot

8条回答
走好不送
2楼-- · 2019-03-27 16:22
Intent.setType("plain/text");

At first when I spotted this I immediately though it was a mistake and it was meant to be text/plain, but this is actually the correct way to only display E-mail clients in the application list.

Give it a try and see for yourself.

查看更多
冷血范
3楼-- · 2019-03-27 16:25
String rec[] = { owner.email };
i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822") ;
i.putExtra(android.content.Intent.EXTRA_EMAIL, rec);
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "RE: " + desc);
i.putExtra(android.content.Intent.EXTRA_TEXT,
        "\n\n\nSent from Mojo for Android");
startActivity(i);

try this;:::

查看更多
一纸荒年 Trace。
4楼-- · 2019-03-27 16:35
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("mailto:?to=email&subject=hello&body=hello%20world"));
startActivity(Intent.createChooser(intent, "Send via..."));

you can try this:::::

查看更多
唯我独甜
5楼-- · 2019-03-27 16:40
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "abc@xyz.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Subject of the Mail");
emailIntent.putExtra( android.content.Intent.EXTRA_TEXT,
                           "This is my sample Mail");
emailIntent.setType("vnd.android.cursor.dir/email");
startActivity(Intent.createChooser(emailIntent, "Email:"));

else use this it will shows only the mail clients,

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "abc@xyz.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Subject of the Mail");
emailIntent.putExtra( android.content.Intent.EXTRA_TEXT,
                           "This is my sample Mail");
//emailIntent.setType("vnd.android.cursor.dir/email");
startActivity(Intent.createChooser(emailIntent, "Email:"));
查看更多
劫难
6楼-- · 2019-03-27 16:41

It will show all the available app installed on android phone which can perform sharing or send a link from webview to others. Like - Gmail, facebook, imo, whatsapp, messenger etc.

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String shareLink = webView.getUrl();
intent.putExtra(Intent.EXTRA_TEXT, shareLink);
startActivity(Intent.createChooser(intent, "Share via..."));
查看更多
小情绪 Triste *
7楼-- · 2019-03-27 16:43

As long as you are using ACTION_SEND with type text/plain, it will show all the valid options. However, if you want, you may design your your own dialog window which shows only Gmail or other mail client by doing filtering programatically.

BTW, why do you even need this window when you just want to use Gmail?

查看更多
登录 后发表回答