我想從我的應用程序中的drawables共享圖像。我不斷收到java.io.FileNotFoundException:/abc.jpg (read-only file system)
Android圖像發送意圖
我的代碼
private String SaveCache(int resID) {
String path = "";
try {
InputStream is = getResources().openRawResource(resID);
File cacheDir = this.getExternalCacheDir();
File downloadingMediaFile = new File(cacheDir, "abc.jpg");
byte[] buf = new byte[256];
FileOutputStream out = new FileOutputStream(downloadingMediaFile);
while (true) {
int rd = is.read(buf, 0, 256);
if (rd == -1 || rd == 0)
break;
out.write(buf, 0, rd);
}
is.close();
out.close();
return downloadingMediaFile.getPath();
} catch (Exception ex) {
Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
ex.printStackTrace();
}
return path;
}
private void ImageShare() {
String path = SaveCache(R.drawable.testsend);
Toast.makeText(this, path, Toast.LENGTH_LONG).show();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_SUBJECT, "test");
share.putExtra(Intent.EXTRA_TEXT, "test");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + path));
try {
startActivity(Intent.createChooser(share, "Choose share method."));
} catch (Exception ex) {
ex.printStackTrace();
}
}
任何幫助表示讚賞,如果有更多的信息需要,我會很樂意提供。
當你花一個小時搗亂鍵盤找出這個愚蠢的小錯誤時,你不覺得討厭它嗎?在檢查外部存儲的過程中,我發現我忘了添加外部存儲的權限。 – zaid