ファイルをインテント内で取得する最も保証された方法は、ストリームを開いてアプリのプライベートフォルダにコピーすることです。
この方法は、ローカルファイル、content
uri、picasa、すべてのために機能します。そのような
何か:
private File getSharedFile() {
Uri uri = intent.getExtras().getParcelable(Intent.EXTRA_STREAM);
// or using the new compat lib
Uri uri = ShareCompat.IntentReader(this).getStream();
InputStream is = null;
OutputStream os = null;
try {
File f = ... define here a temp file // maybe getCacheDir();
is = getContentResolver().openInputStream(uri);
os = new BufferedOutputStream(new FileOutputStream(f));
int read;
byte[] bytes = new byte[2048];
while ((read = is.read(bytes)) != -1) {
os.write(bytes, 0, read);
}
return f;
} catch (Exception e) {
... handle exceptions, buffer underflow, NPE, etc
} finally {
try { is.close(); } catch (Exception e) { /* u never know */ }
try {
os.flush();
os.close();
} catch (Exception e) { /* seriously can happen */ }
}
return null;
}
あなたはファイルエクスプローラのAndroidデバイスモニタを使用してフォルダを作成することができます。 (デバイスマネージャとSDKマネージャの横にある小さなアンドロイドのアイコン) –