1

私はこのソリューションを使用しています。

i.putExtra(Intent.EXTRA_TEXT , "body of email");期待どおりに動作しています。"body of email"長さが 711098 の文字列に変更された場合は、そうでない場合よりも、電子メール クライアント チューザーに表示されません。

アイデア、解決策はありますか?

4

2 に答える 2

2

Intentオペレーション (例: ) で使用される は、最大startActivity()1MB に制限されています。

それを克服する方法は?

もっと短いメールを送ってください。

または、 を使用して長いテキストを添付ファイルとして送信しますEXTRA_STREAM

または、JavaMail を使用して電子メールを送信します。

または、アプリの代わりにメールを送信する Web サービスに 711098 バイトを送信して、メールを送信します。

于 2013-09-02T15:49:31.523 に答える
0

CommonsWareが提案したものの実装は 次のとおりです。

一時ファイルはダウンロード フォルダーに保存されるため、すべてのアプリからアクセスできます。削除することを忘れないでください!

開発時には、USB ケーブルがデバイスに接続され、logcat を監視しています。ここで USB ケーブルを抜きます。そうしないと、アクセス許可拒否の例外が発生します。

data.txt は Gmail クライアント インターフェースに表示されますが、ケーブルを抜くのを忘れて Android OS が彼のダウンロード フォルダにアクセスできるようにしておくと送信されません。

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 に答える