0
嗨我在我的應用程序中有一個畫廊,當您單擊縮略圖時在圖像視圖中顯示圖像。我正在爲一個警告對話框設置一個長單擊偵聽器,該對話框有2個按鈕,一個用於設置壁紙,另一個用於分享。我有共享意圖和獲取圖形緩存有點工作。它適用於模擬器,但不適用於我的手機。我已經在這個網站上使用了很多例子來實現這個目標,但是它根本不工作。它保持關閉我的手機上的應用程序的力量。任何幫助表示讚賞。Android只讀文件系統錯誤
alertDialog.setButton2("Share",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
imgView.setDrawingCacheEnabled(true);
Bitmap b = imgView.getDrawingCache();
File sdCard = Environment.getExternalStorageDirectory();
File file = new File(sdCard.getAbsolutePath() + "image.jpg");
try {
file.createNewFile();
OutputStream fos = null;
fos = new FileOutputStream(file);
b.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d("Save Example", "Image saved.");
Intent shareIntent = new Intent(Intent.ACTION_SEND);
Uri phototUri = Uri.parse("file:///sdcard/image.jpg");
shareIntent.setData(phototUri);
shareIntent.setType("image/jpeg");
shareIntent.putExtra(Intent.EXTRA_STREAM, phototUri);
startActivity(Intent.createChooser(shareIntent, "Share Via"));
}
});
alertDialog.show();
return true;
}
});
更新:它似乎是一個問題,
b.compress(CompressFormat.JPEG, 95, fos);
口口聲聲說空指針。
原來,空指針實際上是一個read_only錯誤。所以它沒有實際寫入文件,我得到一個ioexception只讀文件系統。它爲什麼這樣做?
在嘗試寫入之前,您需要查看目錄的權限。您必須瞭解UNIX的基本文件系統權限才能執行此分析。 – JoxTraex 2012-03-21 05:49:41
你在清單文件中使用寫入權限? – 2012-03-21 05:54:07
是的,我在清單中有write.external.storage – Pestilence 2012-03-21 14:30:59