I'm trying to save an image coming from the API into the phone's memory.
public void saveSkin() {
ivSkinSaver.buildDrawingCache();
Bitmap bm = ivSkinSaver.getDrawingCache();
OutputStream Out = null;
try {
File mediaFile;
File mediaStorageDir = new File(Environment.getExternalStorageDirectory()
+ "/Android/data"
+ getApplicationContext().getPackageName()
+ "/Files");
String timeStamp = new SimpleDateFormat("dd/MM/yyyy_HH:mm_").format(new Date());
String mImageName = timeStamp + stringSkin;
mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName);
mediaFile.createNewFile();
Out = new FileOutputStream(mediaFile);
Toast.makeText(getBaseContext(),"file saved",Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(this, "Error occured. Please try again later." + e.getStackTrace(),
Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
try {
bm.compress(Bitmap.CompressFormat.PNG, 100, Out);
Out.flush();
Out.close();
} catch (Exception e) {
}
}
}
I used e.printStackTrace()
and the result is: "java.io.IOException: open failed: EACCES (Permission denied)"