I'm trying to save my bitmap to a file, but the android studio throws an exception java.io.FileNotFoundException: /storage/emulated/0/Pictures/savedBitmap.png (Permission denied)
What am I doing wrong?
public void save(){
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "savedBitmap.png");
if (file.exists()){
Log.i(TAG, "file is exists");
} else {
Log.i(TAG, "file is not exists");
}
try {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
} finally {
if (fos != null) fos.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
2019-04-30 13:03:03.058 22470-22470/com.example.paint I/PaintView: file is not exists
2019-04-30 13:03:03.059 22470-22470/com.example.paint W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Pictures/savedBitmap.png (Permission denied)