0

I have an app that needs to write files to external storage. In manifest I've added

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

In the activity I am calling

ActivityCompat.requestPermissions(this, STORAGE_PERMISSIONS, PERMISSION_REQUEST_RW_EXTERNAL_STORAGE);

Where:

private static final int PERMISSION_REQUEST_RW_EXTERNAL_STORAGE = 783;
private static final String[] STORAGE_PERMISSIONS = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE};

Of course I'm granting everything and I can see in "onRequestPermissionsResult" the grants received by the app. After all of that, when trying to create a file in external storage I am getting permissions denied.

java.io.IOException: Permission denied

Running on:

Android 8 (Oreo)
compileSdkVersion 27
minSdkVersion 23
targetSdkVersion 27

EDIT: I am trying to write this directory: /storage/emulated/0/6666-6433/DCIM/Camera/. In previous state I'm listing video files on local storage and getting files in this directory. reading the files using this path is working as expected.

Idan
  • 2,819
  • 4
  • 33
  • 61
  • Post the error message too :) – DataDino Sep 15 '18 at 20:47
  • @DataDino Updated. It's a standard IOException: "java.io.IOException: Permission denied" – Idan Sep 15 '18 at 20:52
  • Where are you trying to write to inside of the SDCard? It's possible you might be writing on to a private external directory of another app. Also does the phone/emulator have an SDCard? Some general tips: https://developer.android.com/training/data-storage/files#WriteExternalStorage – DataDino Sep 15 '18 at 22:27
  • A quick check worth doing: Go to the Apps in Settings and select your application. See if the permission is really turned on. Easiest way to check if the permission is being granted. – theblitz Sep 15 '18 at 23:23
  • @DataDino Updated the question. I'm writing to this folder: /storage/emulated/0/6666-6433/DCIM/Camera/ – Idan Sep 16 '18 at 05:11
  • @theblitz Checked. Granted. – Idan Sep 16 '18 at 05:12
  • @Idan Looks like you've run into the Android Storage Access framework. You must use the APIs listed in the link above, and also you are not allow to write to the same top-level directory that the Camera app uses. See: https://stackoverflow.com/questions/41782162/how-to-write-file-into-dcim-directory-exactly-where-camera-does – DataDino Sep 16 '18 at 23:09

0 Answers0