Send Email Intent

前端 未结 30 3640
忘掉有多难
忘掉有多难 2020-11-22 07:27
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(\"text/html\");
intent.putExtra(Intent.EXTRA_EMAIL, \"emailaddress@emailaddress.com\");
intent.putExtr         


        
30条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 08:08

    If you want to ensure that your intent is handled only by an email app (and not other text messaging or social apps), then use the ACTION_SENDTO action and include the "mailto:" data scheme. For example:

    public void composeEmail(String[] addresses, String subject) {
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:")); // only email apps should handle this
        intent.putExtra(Intent.EXTRA_EMAIL, addresses);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    }
    

    I found this in https://developer.android.com/guide/components/intents-common.html#Email

提交回复
热议问题