0

重複の可能性:
Intent を使用した Android の複数の電子メール添付ファイル

回答の1つから現在のコードを取得したため、同様の質問がある可能性があることは既に知っています。しかし、私はいくつかの問題に直面しており、最初はGmailアプリの問題だと思いますが、他の電子メールクライアントと同じ問題で試しました. コード: -

ArrayList<Uri> uris = null;
        try {
            uris = logger.getSiteFilePaths(siteIndex);
        } catch (BaseLoggerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Intent emailIntent = new   Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
        emailIntent.setType("application/octet-stream");
        emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
        emailIntent.putExtra(Intent.EXTRA_EMAIL,"");
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Bl\u00fc-Test Log");
        emailIntent.putExtra(Intent.EXTRA_TEXT, "Please find the attachments.");
        emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        startActivity(Intent.createChooser(emailIntent, "Email:"));

ファイルパスは正確です

**e.g. --** file:///storage/sdcard0/BAPISandy_test1.csv

問題:- Gmail アプリではファイルが添付されているように見えますが、メールを送信すると、通知バーに「添付ファイルを表示できませんでした」と表示されます。他の電子メール クライアントで試した場合、ファイルが添付ファイルとして表示されません。 システム情報:-- Samsung Galaxy Tab 2 (7 インチ) Android 4.1.1

4

2 に答える 2

1

私は今日も私のNote2とSG3の顧客と一緒にこれに反則しました。少し掘り下げてみたところ、次のことがわかりました。

外部ストレージデバイス名をリクエストすると-Environment.getExternalStorageDirectory ()。getName()(バージョン7をターゲットにしているのでこれを使用します)-ファイル名を追加してメールまたはGmailに渡すと、「sdcard0」が表示されますその後、どちらも添付ファイルを追加しません。'sdcard0'の末尾のゼロを手動で編集し、'sdcard' +ファイル名を渡すと、すべて正常に機能します。これは、JBの前、または常に「sdcard」を返すエミュレーターのJBでこのコードを実行した場合、問題にはならないようです。

私が使用することになっている別のコードがあるかどうか、またはこれがOSがパスを報告し、電子メールシステムがそれを使用する方法に矛盾があるかどうかはわかりません。(sdcard0はsdcardと同じ場所を指すはずだと思っていましたが、何かが機能していません)

コードにパッチを当ててゼロを取り除くことができます(これは醜くて危険です)。他の誰かが明るいアイデアを持っていない限り:)

編集:他の誰かがそれが役に立つと思うかもしれない場合に備えて、私は以下に私のコードを追加しました。

                    // try and grab the log file

            String logFile = File.separator + getResources().getString(R.string.app_name) + File.separator + "logs" + File.separator + Constants.SMS_FILE;
            String extStorage = Environment.getExternalStorageDirectory().getName();

            // The following is a kludge for the Samsung (and maybe more) JB devices that don't allow you to add a file with the SDCARD0 external storage
            // link

            File nf = new File(extStorage, logFile);
            if (!nf.exists()) {
                // OK we can't find the file - say so and see if we are hiding behind SDCARD0

                Log.w(getLocalClassName() + ".shouldOverrideUrlLoading", "File: " + extStorage + logFile + " Doesn't exist - trying again");
                if (extStorage.matches("(?i)SDCARD(?-i)[0-9]")) {
                    // OK we've got a SDCARDx scenario - let's see if the file exists without the x
                    String extStorageFix = extStorage.replaceFirst("(?i)SDCARD(?-i)[0-9]", extStorage.substring(0, 6)); // try it without the 0,1,2 etc
                    nf = new File(extStorageFix, logFile);
                    if (!nf.exists()) {
                        // OK we're in the pooh now - can't find the log file so just say so and try to exit without attaching it.
                        Log.w(getLocalClassName() + ".shouldOverrideUrlLoading", "File: " + extStorageFix + logFile + " Doesn't exist either - giving up");
                        Toast.makeText(
                                getApplicationContext(),
                                "Unable to attach Log file from\n" + extStorage + logFile + "\n" + extStorageFix + logFile
                                        + "\nPlease add it manually if possible", Toast.LENGTH_LONG).show();
                    } else {
                        // Hurrah we found it - remember we did so and carry on
                        extStorage = extStorageFix;
                        Log.w(getLocalClassName() + ".shouldOverrideUrlLoading", "Found logfile at: " + extStorage + logFile);
                    }
                }

            }

            if (Debug.ON) {
                Log.d(getLocalClassName() + ".shouldOverrideUrlLoading", "Filepath = " + "file://" + File.separator + extStorage + logFile);
            }
            i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + File.separator + extStorage + logFile));**strong text**
于 2013-01-23T20:19:50.663 に答える
1

"/"申し訳ありませんが、実際に問題を引き起こしているファイルパスの欠落などの小さなバグを見つけるのは困難です。

于 2013-01-15T13:28:12.807 に答える