I try to download an image with this code and save it :
in this line:
OutputStream os =new FileOutputStream(f);
i try it on the emulator.my app get exception that there is no permission to save to this path:
java.io.FileNotFoundException: /mnt/sdcard/InterFlora/1221618532: open failed: EACCES (Permission denied)
i also add this line :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
this is the code:
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;
}
}
}
Edit
File m_Sdcard = Environment.getExternalStorageDirectory();
File cacheDir =new File (m_Sdcard.getAbsolutePath() + "/MyFolder");
if(!cacheDir.exists())
cacheDir.mkdirs();
1 Answer