私は今日も私の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**