ACTION_SEND force sending with email

前端 未结 9 1931
予麋鹿
予麋鹿 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:19

    I think you should change the setType to

    i.setType("message/rfc822") ;
    
    0 讨论(0)
  • 2021-02-15 12:21

    Even though it's too late for @thepoosh, but it may be helpful for future questioners. After a lot of searching and testing, I finally found a good solution. Thanks to the Open source developer, cketti for sharing his/her concise solution.

    String mailto = "mailto:bob@example.org" +
        "?cc=" + "alice@example.com" +
        "&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
    }
    

    This is the link to his/her gist.

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

    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?

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

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

    Try to setType message/rfc822 instead of text/plain

    0 讨论(0)
  • 2021-02-15 12:31
    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:"));
    
    0 讨论(0)
提交回复
热议问题