1

我正在使用这个解决方案。

i.putExtra(Intent.EXTRA_TEXT , "body of email");它按预期工作。如果"body of email"更改为长度为 711098 的字符串,则:它不会出现在电子邮件客户端选择器中。

任何想法,解决方案?

4

2 回答 2

2

操作中使用Intent的 (例如,startActivity())限制为 ~1MB。

如何克服它?

发送较短的电子邮件。

或者,将长文本作为附件发送,使用EXTRA_STREAM.

或者,使用 JavaMail 发送电子邮件。

或者,通过将 711098 字节发送到您操作的代表您的应用程序发送电子邮件的 Web 服务来发送电子邮件。

于 2013-09-02T15:49:31.523 回答
0

这是建议的 CommonsWare的实现:

临时文件保存到您的“下载”文件夹中,因此所有应用程序都可以访问它。不要忘记删除它!

在开发时,USB 电缆已插入您的设备,您正在观看 logcat。现在拔出 USB 电缆,否则您将收到 Permission denied 异常!

data.txt 将在 Gmail 客户端界面中可见,但如果您忘记拔出电缆并让 Android 操作系统访问他的下载文件夹,它将不会发送。

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);
    }
于 2013-09-02T17:14:52.843 回答