ACTION_SEND force sending with email

前端 未结 9 1898
予麋鹿
予麋鹿 2021-02-15 11:37

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 onl

相关标签:
9条回答
  • 2021-02-15 12: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:::::

    0 讨论(0)
  • 2021-02-15 12:35
    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.

    0 讨论(0)
  • 2021-02-15 12:35

    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..."));
    

    But when you force to open mail app only :

    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:"));
    intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"something@gmail.com"});
    
    try {
        startActivity(Intent.createChooser(intent, "send mail"));
    } catch (ActivityNotFoundException ex) {
        Toast.makeText(this, "No mail app found!!!", Toast.LENGTH_SHORT);
    } catch (Exception ex) {
        Toast.makeText(this, "Unexpected Error!!!", Toast.LENGTH_SHORT);
    }
    
    0 讨论(0)
提交回复
热议问题