ACTION_SEND force sending with email

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

提交回复
热议问题