[使用Intent发送带有设备信息的电子邮件

问题描述 投票:0回答:1

当用户单击某个电子邮件地址时,我想将电子邮件发送到特定的电子邮件地址,但是当我单击发送时,电子邮件字段为空白

String deviceInfo="Device Info:";
    deviceInfo += "\n OS Version: " + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")";
    deviceInfo += "\n OS API Level: " + android.os.Build.VERSION.SDK_INT;
    deviceInfo += "\n Device: " + android.os.Build.DEVICE;
    deviceInfo += "\n Model (and Product): " + android.os.Build.MODEL + " ("+ android.os.Build.PRODUCT + ")";

    Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
    emailIntent.setData(Uri.parse("mailto:"));
    emailIntent.putExtra(Intent.EXTRA_EMAIL, "[email protected]");
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
    emailIntent.putExtra(Intent.EXTRA_TEXT, deviceInfo);
    if (emailIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        startActivity(emailIntent);
    }
java android android-studio email android-intent
1个回答
0
投票

使用以下方法:

Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse(String.format("mailto:%s", "[email protected]")));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, deviceInfo);
© www.soinside.com 2019 - 2024. All rights reserved.