1

I am using This solution.

At i.putExtra(Intent.EXTRA_TEXT , "body of email"); it is working as expected. If "body of email" is changed to String with 711098 lengths than not: it is not coming up the email client chooser.

Any ideas, solutions?

Community
  • 1
  • 1

2 Answers2

2

An Intent used in an operation (e.g., startActivity()) is limited to ~1MB.

How to overcome it?

Send a shorter email.

Or, send the long text as an attachment, using EXTRA_STREAM.

Or, send the email using JavaMail.

Or, send the email by shipping up the 711098 bytes to a Web service that you operate that sends the email on your app's behalf.

CommonsWare
  • 910,778
  • 176
  • 2,215
  • 2,253
  • thanks, I will check: the send the long text as an attachment, using EXTRA_STREAM –  Sep 02 '13 at 15:50
  • could you please check the implementation, what is missing from there? –  Sep 02 '13 at 16:27
0

Here is an implementation of what have suggested CommonsWare:

The temp file is saved to your Downloads folder, so it is accessible for all apps. Do not forget to delete it!

At development time the USB cable is plugged to your device and you are watching the logcat. Now pull out the usb cable or you will get a Permission denied exception!

The data.txt it will be visible at Gmail client interface, but it will not send if you forget to pull out the cable and let the Android OS have access to his Downloads folder.

public void sendEmail(String emailBody, String emailAddrressTo) {

        boolean bodyToLong = (emailBody != null && emailBody.length() > 300000);

        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { emailAddrressTo });
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "data");
        if (!bodyToLong) {
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody);
        } else {// data file to big:

            String tmpFileName = "data.txt";
            File dirDownloads = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
            File fileOut = new File(dirDownloads, tmpFileName);

            FileOutputStream fos;
            try {
                fileOut.createNewFile();
                fos = new FileOutputStream(fileOut);

                FileDescriptor fd = fos.getFD();
                BufferedWriter bw = new BufferedWriter(new FileWriter(fd));
                bw.write(emailBody);

                fd.sync();
                bw.close();

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                String msg = e.getMessage();
                if (msg.contains("(Permission denied)")) {
                    Toast.makeText(activity, "PULL THE USB CABLE OUT FROM PHONE!!! Out You have forgot to add android.permission.WRITE_EXTERNAL_STORAGE  permission to AndroidManifest.xml", Toast.LENGTH_SHORT).show();
                }

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This message has to long data. Please see the attachment!");

            Uri uri = Uri.fromFile(fileOut);
            emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
        }
        emailIntent.setType("message/rfc822");

        Intent intentToStart = Intent.createChooser(emailIntent, "Send mail...");

        activity.startActivity(intentToStart);
    }
Community
  • 1
  • 1