1

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!

rajrathod
  • 89
  • 8
  • Since [neither `EXTRA_SUBJECT` nor `EXTRA_TEXT` are documented to be supported by `ACTION_SENDTO`](https://developer.android.com/reference/android/content/Intent.html#ACTION_SENDTO), I do not know why you would expect this to work reliably across email clients. Whether any given app wishes to try handling undocumented extras is up to the developers of that app. – CommonsWare Mar 15 '20 at 11:33
  • @CommonsWare Thanks for comment and point. As I have told its working fine in one of my app with build version till 28. I am facing issue in 29.0.2 Thanks! – rajrathod Mar 15 '20 at 11:36
  • @CommonsWare You can see EXTRA_SUBJECT [here](https://developer.android.com/reference/android/content/Intent#EXTRA_SUBJECT) – rajrathod Mar 15 '20 at 11:39
  • "As I have told its working fine in one of my app with build version till 28" -- not really. There are dozens, if not hundreds, of apps that the user might choose to respond to `ACTION_SENDTO` for a `mailto:` `Uri`. None have to honor those undocumented extras. "You can see EXTRA_SUBJECT here" -- you cannot see `EXTRA_SUBJECT` [here](https://developer.android.com/reference/android/content/Intent.html#ACTION_SENDTO), in the documentation for `ACTION_SENDTO`. That extra does not have to be honored by any `ACTION_SENDTO` apps. – CommonsWare Mar 15 '20 at 11:40
  • You are certainly welcome to include `EXTRA_SUBJECT` on your `ACTION_SENDTO` `Intent`. Many apps will ignore it, and you will have to learn to live with that limitation. If you use `ACTION_SEND` instead of `ACTION_SENDTO`, *then* `EXTRA_SUBJECT` is expected to work. Even then, buggy apps might ignore it. – CommonsWare Mar 15 '20 at 11:42
  • Posible duplicate or same subject as: https://stackoverflow.com/questions/59836984/email-body-empty-when-select-to-send-email-by-gmail/59837227#59837227 – Mihai Neacsu Mar 15 '20 at 12:21

1 Answers1

1

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.

Ezzy
  • 1,423
  • 2
  • 15
  • 32
  • Hello! What is Const.RC_PRODUCT_REQUEST and How I can use it? Thanks! – rajrathod Mar 15 '20 at 12:31
  • @rajrathod that's the request code for the intent. Const.RC_PRODUCT_REQUEST is just a file of codes that I have. You can put any value in there and get the result of the intent in the onActivityResult function. https://developer.android.com/training/basics/intents/result – Ezzy Mar 15 '20 at 12:33
  • I have removed ActivityResult code and used without it and its working fine as I was looking. Thanks a lot :) – rajrathod Mar 15 '20 at 12:34