Q: Permission denied creating new File Android Marshmallow after asking WRITE_EXTERNAL_STORAGE permission My app is targeting SDK 23. I am trying to take a photo and I check if I got the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions. If it does not have these permissions it will request them using following line.
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, 12);

I check if the permission was accepted/allowed using the onRequestPermissionsResult method callback.
If it was accepted I use the following code to create a File. 
// this code only gets called when permission was accepted by the user
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(imageFileName, ".jpg", storageDir);

Strangely enough I get following exception
error while creating file
java.io.IOException: open failed: EACCES (Permission denied)
at java.io.File.createNewFile(File.java:939)
at java.io.File.createTempFile(File.java:1004)

When I fully restart my app, the code just executes fine without any exceptions. I already tried to execute the code in another activity. It opens the activity when the permission was allowed, but than still I get that permission denied exception.
Am I doing anything wrong, could the problem be the emulator?
