我嘗試下載的圖像與此代碼並保存: 在這一行:無法保存圖片到SD卡
OutputStream os =new FileOutputStream(f);
我嘗試它的emulator.my應用得到不同的是沒有權限保存到該路徑:
java.io.FileNotFoundException: /mnt/sdcard/InterFlora/1221618532: open failed: EACCES (Permission denied)
我也加入這一行:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
這是代碼:
RetreiveImage extends AsyncTask<String, Void,Bitmap> {
Item m_item;
File f;
public RetreiveImage(Item aItem , File aFile){
m_item = aItem;
f = File (m_Sdcard.getAbsolutePath() + "/myFolder");
}
@Override
protected Bitmap doInBackground(String... params) {
try
{
Bitmap bitmap=null;
InputStream is=new URL(m_item.small).openStream();
OutputStream os =new FileOutputStream(f);
os.close();
return bitmap;
}
catch (MalformedURLException e) {
return null;
} catch (IOException e) {
return null;
}
}
}
編輯
File m_Sdcard = Environment.getExternalStorageDirectory();
File cacheDir =new File (m_Sdcard.getAbsolutePath() + "/MyFolder");
if(!cacheDir.exists())
cacheDir.mkdirs();
你應該添加android.permission.WRITE_EXTERNAL_STORAGE權限清單文件 – 2012-02-17 19:25:16
我加入這行已經 – MTA 2012-02-17 19:32:08
顯示你的清單,並在那裏你加入這行 – 2012-02-17 19:35:02