I am getting the following error when I try to write to a File:
java.io.FileNotFoundException: /storage/extSdCard/DCIM/Camera/20160314_231954.jpg: open failed: EACCES (Permission denied)
The code I am using to write it is this:
// The correctURIString was obtained earlier, in my example here, it is:
// /storage/extSdCard/DCIM/Camera/20160314_231954.jpg
file = new File(correctURIString);
out1 = new FileOutputStream(file);
//The b is a Bitmap that I was creating (rotating 90 Degrees)
b.compress(Bitmap.CompressFormat.JPEG, 90, out1);
First off, let me tell you what I have done thus far:
My manifest IS including the permissions requests;
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
And they are located just outside of the Application tag.
I've also tried all of the recommendations in these threads:
1) java.io.filenotfoundexception open failed eacces (permission denied) on device
2) Permission denied when writting into sdCard
3) Exception 'open failed: EACCES (Permission denied)' on Android
4) Getting rotation from ExifInterface always returns 0
5) Android Exception : java.io.IOException: open failed: EACCES (Permission denied)
The issue here is that if I use my file explorer program (Astro File Manager btw) to find this exact photo, the ACTUAL location is listed as:
"3261-3265/DCIM/Camera/20160314_231954.jpg"
Which is nothing matching what I am getting via the attempts to get Absolute Paths. The code I am using to get the absolute path is:
public String getAbsolutePath(Uri uri) {
if(Build.VERSION.SDK_INT >= 19){
String id = uri.getLastPathSegment();
//Custom function here, just keeps the numbers (removes everything else)
id = StringUtilities.keepNumbersOnly(id);
final String[] imageColumns = {MediaStore.Images.Media.DATA };
final String imageOrderBy = null;
Uri tempUri = getUri();
Cursor imageCursor = getActivity().getContentResolver().query(tempUri, imageColumns,
MediaStore.Images.Media._ID + "=" + id, null, imageOrderBy);
if (imageCursor.moveToFirst()) {
return imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
}else{
return null;
}
}else{
String[] projection = { MediaStore.MediaColumns.DATA };
Cursor cursor = getActivity().getContentResolver().query(uri, projection, null, null, null);
if (cursor != null) {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} else
return null;
}
}
This absolute path for this particular photo is being returned as:
/storage/extSdCard/DCIM/Camera/20160314_231954.jpg
As you can see, this absolute location does not match the actual one, hence, it is not working. I am unsure how to make this work properly.
Does anyone have any idea how to correctly get the absolute path that is correct?
Thanks for the help all.
-Sil
Edit: This was marked as duplicate citing this link:
java.io.filenotfoundexception open failed eacces (permission denied) on device
Which was already discussed in the question where I indicated I had tried the answers there without success. (See question)
As of 2017-03-02, this has not been solved, but wanting to clarify that it was not a duplicate.