我想寫一個位圖在Android上的SD卡,我得到我宣佈在清單中的android.permission.WRITE_EXTERNAL_STORAGE
許可
/mnt/sdcard/PhysicsSketchpad/sketchpad145.png (No such file or directory).
錯誤信息,這是我的代碼:的Android寫的位圖到SD卡
String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() +
"/PhysicsSketchpad/";
File dir = new File(file_path);
dir.mkdirs();
File file = new File(dir, "sketchpad" + pad.t_id + ".png");
FileOutputStream fOut = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
發生了什麼事?
UPDATE
它好像當我嘗試寫現有的目錄,我得到否定錯誤的許可,
08-11 09:55:23.796: WARN/Physics Sketchpad(8881): Error when saving: IOException /mnt/sdcard/download/sketchpad54.png (Permission denied)
,當我嘗試在保存新目錄我得到一個沒有這樣的文件或目錄錯誤,08-11 09:59:20.175: WARN/Physics Sketchpad(9040): Error when saving: IOException /mnt/sdcard/PhysicsSketchpad/sketchpad55.png (No such file or directory)
另外,File.mkdirs()
根據成功與否返回布爾值,並返回false。
我發現這個問題!我的使用許可標籤位於我的應用程序標籤中。雖然它沒有直接解決我的問題,但Ilango的回答和評論對我最有幫助。 – zim333311