Reputation: 343
I have an application that in the login I download images from my server. in the first login, everything is work fine but when I uninstall the application and install it again I get this exception:
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.gilapp.android.app/files/images/book_118.png: open failed: EACCES (Permission denied)
and can't save the image.
this happen while I'm trying to create output stream:
OutputStream output = new FileOutputStream(filePath);
The images download fine just when I do the second installation after I go to App info -> Storage -> clear data
Another important point is that it happens only in Samsung's tablet: SM-T800 (API level 23)
In other devices it's not happening, the devices that I test: Samsung SM-G900H (API level 23)
, Asus P028 (API level 24)
, Samsung SM-G950F (API level 28)
Upvotes: 0
Views: 12016
Reputation: 1530
First, check whether you have implemented scoped storage logic in the app. You can also use android:requestLegacyExternalStorage="true" But this legacyStoragePermission is limited to version 10. You need to implement scoped logic.
Also, check whether your targetSDKVersion value is 30 or greater or not, this is needed if you are using the app in Device android version 30 or more.
Upvotes: 1
Reputation: 777
If your app is pointing to the android version 10.
In the manifest include under the application add
android:requestLegacyExternalStorage="true"
Note that this workaround no longer works in Android 11.
Upvotes: 12
Reputation: 9292
When you uninstall your application all files in getExternalFilesDir()
are removed hence the /images
directory has gone
After reinstall you can again write files to that directory for which you do not need any permission.
Not at runtime. Not in manifest.
But you want them in the ..../images directory.
You have to care for that directory yourself.
Check if the directory exists and then create it before you try to put a file in it.
Upvotes: 1
Reputation: 1431
You need to get Run-time permission for write in storage. before saving your files check the permission.also there are some library for this work: Android-Arsenal
is better to use a FileProvider for accessing files in storage.
Upvotes: 1