简体   繁体   中英

Open Email using Android Intent

I am using below codes for send feedback of my application via email intent. It was working fine till build version 28. But in Android 29, I am not getting subject and body text include during open the email app, its showing to email address only not other text. My code is like below

 String appName = getResources().getString(R.string.app_name);
                        int versionCode = BuildConfig.VERSION_CODE;
                        String versionName = BuildConfig.VERSION_NAME;
                        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 + ")";
                        deviceInfo += "\n App Version Code: " + versionCode;
                        deviceInfo += "\n App Version Name: " + versionName;
                        Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "myemail@gmail.com", null));
                        emailIntent.putExtra(Intent.EXTRA_SUBJECT, appName + " Problem");
                        emailIntent.putExtra(Intent.EXTRA_TEXT, "write your issue here \n\n\n______________________________\n\n" + deviceInfo);

                        startActivity(Intent.createChooser(emailIntent, "Send email..."));

I am not getting any error in logcat. Let me know if anyone can help me for solve the issue. Thanks!

I would recommend putting everything in the intent data like this

Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
String mailTo = "mailto:example@example.com" +
        "?cc=" + "" +
        "&subject=" + Uri.encode("Email subject") +
        "&body=" + Uri.encode("Email body");
emailIntent.setData(Uri.parse(mailTo));

// For result
startActivityForResult(Intent.createChooser(emailIntent, "Send email"), 100);

// Without result
startActivity(Intent.createChooser(emailIntent, "Send email"));

It works fine and most, if not all email clients should pick that up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM