Skip to content
Advertisement

java.io.FileNotFoundException open failed: EEXIST (File exists) Android 11

I was trying to download an image from a server and save it in the external memory, but in Android 11 it gives me an error when I try to create the file. I have granted permission to access the external storage.

i searched a bit on the internet and they suggested me to put this code in the manifest, but it didn’t work for android 11

JavaScript

manifest

JavaScript

MainActivity

JavaScript

writeResponseBody

JavaScript

error

JavaScript

Advertisement

Answer

In Android 11 android:requestLegacyExternalStorage="true" will simply be ignored, since it was an ad-hoc solution for Android < 11 to not break old apps. Now, you must use

JavaScript

Also you could just use SAF to avoid all this ‘permissions’ hassle. This is what Google recommends for apps that do not need to manage most internal storage data. Refer to: https://developer.android.com/guide/topics/providers/document-provider

However, if you don’t want to break you app and lose all your hard work, consider

JavaScript

This will bring up a settings page where you will be able to give storage access to your app. If the app already has permission, then you will be able to access the directory. Place this at the very beginning of onCreate() method after setting layout resource.

It’s best not to do this for any future apps you build.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement