Home > database >  android-writing to a file denied in sd card
android-writing to a file denied in sd card

Time:04-09

i'm trying to develop a simple file encrypter-decrypter app. on android devices.user picks whichever file he/she wants and encrypt or decrypt it using aes.this process is allowed for internal storage but when i choose a file in sd card it causes an error i can't find a solution for a long time.

i have permissions in manifest.xml:

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

also i ask user for runtime permissions(despite user allows permissions the result is "permission denied" error).

the error generated in th log is:

W/System.err: java.io.FileNotFoundException: storage/3962-3235/Download/dummyFileEncrypted.txt: open failed: EACCES (Permission denied)

where the error occurs in the encrypt function while the output file is being created, with line:

FileOutputStream outputStream=new FileOutputStream(outputFile);

as i said process works perfectly when i pick a file from internal storage.

any advice would be welcome. thanks in advance.

CodePudding user response:

Yes, micro sd cards are read only since Android KitKat.

Only one app specific directory is writable for your app.

Have a look at the second item returned by getExternalFilesDirs() for writable location.

Or use Storage Access Framework if you wanna write at other locations.

CodePudding user response:

You should check they, I recommend using framework.

  • Related