Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 11 open failed: EACCES (Permission denied)

I am developing an app. In which I am uploading different file types (e.g. docx, pdf, zip) to a WAMP Server. Below is path of file to my internal Storage.

/storage/emulated/0/WhatsApp/Media/WhatsApp Documents/api.txt

I have added and allowed storage permission in Manifest file and also on runtime for reading a file. However there is no Internal Storage Permission request available.

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

and also for Android 10 I was using this attribute also

android:requestLegacyExternalStorage="true"

But i am getting this error on Android 11 OS a.k.a Android R onboard Samsung Galaxy when I am reading file from Internal Storage for uploading.

java.io.FileNotFoundException: /storage/emulated/0/WhatsApp/Media/WhatsApp Documents/api.txt: open failed: EACCES (Permission denied)

like image 669
Mohammad Aamir Avatar asked Apr 06 '21 08:04

Mohammad Aamir


People also ask

How do I fix Open failed Eacces permission denied?

Just turn off USB storage, and with the correct permissions, you'll have the problem solved.

How do you fix exception Open failed Eacces permission denied on Android 11 12?

You can try to use the android:preserveLegacyExternalStorage="true" tag in the manifest file in the application tag. This tag is used to access the storage in the android 11 devices.

What are the restrictions of Android 11?

Android 11 introduces a changes and restrictions to enhance user privacy, including the following: One-time permissions: Gives users the option to grant more temporary access to location, microphone, and camera permissions. Permission dialog visibility: Repeated denials of a permission implies "don't ask again."


2 Answers

On An Android 11 device your app only has access to its own files.

And to general mediafies in public directories.

Try to list the files in that whatsapp directory and you will see that they are not listed.

You have two options to read the file.

  1. Let the user pick the file with ACTION_OPEN_DOCUMENT.
  2. Request MANAGE_EXTERNAL_STORAGE in manifest and let the user confirm.
like image 106
blackapps Avatar answered Sep 21 '22 11:09

blackapps


You can try to use the android:preserveLegacyExternalStorage="true" tag in the manifest file in the application tag. This tag is used to access the storage in the android 11 devices. And for more detail follow this link it will explain you more as per your requirement.

I search a lot of time and get the solution that adds <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/> in the manifest file and try to get the file access permission in the android 11 phones. Then you will open and read the file from the storage.

But the thing is that the play store does not allow you to use of the MANAGE_EXTERNAL_STORAGE permission in your app. it will take time to give access to the developer to use it to access all the files. Here the link is

like image 24
Syed Rafaqat Hussain Avatar answered Sep 19 '22 11:09

Syed Rafaqat Hussain