Only Email apps to resolve an Intent

后端 未结 14 1545
执念已碎
执念已碎 2020-12-03 06:30

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

14条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 07:30

    This is an absolutely simple and 100% working approach. Thanks to the Open source developer, cketti for sharing this concise and neat 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
    }
    

    And this is the link to his/her gist.

提交回复
热议问题