0
I’m trying to save an image coming from the API in mobile 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 the e.printStackTrace()
and the result is: "java.io.Ioexception: open failed: EACCES (Permission denied)"
Maybe because you don’t have permission anyway. Check your Manifest if granted write permission on the device: android.permission.WRITE_EXTERNAL_STORAGE
– viana
Also, if you have using Android 6.0 have to grant permission at runtime.
– viana
I already put the WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE but still with the same problem.
– Wellington Yogui
Which version of Android is running the application?
– ramaral
@ramaral is in version 6.0
– Wellington Yogui
@Wellingtonyogui the answer below met you or need some more information?!
– viana