Send Email Intent

前端 未结 30 3620
忘掉有多难
忘掉有多难 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:03

    Edit: Not working anymore with new versions of Gmail

    This was the only way I found at the time to get it to work with any characters.

    doreamon's answer is the correct way to go now, as it works with all characters in new versions of Gmail.

    Old answer:


    Here is mine. It seems to works on all Android versions, with subject and message body support, and full utf-8 characters support:

    public static void email(Context context, String to, String subject, String body) {
        StringBuilder builder = new StringBuilder("mailto:" + Uri.encode(to));
        if (subject != null) {
            builder.append("?subject=" + Uri.encode(Uri.encode(subject)));
            if (body != null) {
                builder.append("&body=" + Uri.encode(Uri.encode(body)));
            }
        }
        String uri = builder.toString();
        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
        context.startActivity(intent);
    }
    

提交回复
热议问题