Home > other >  How use File("/sdcard/myfile") without READ_EXTERNAL_STORAGE on android 11?
How use File("/sdcard/myfile") without READ_EXTERNAL_STORAGE on android 11?

Time:01-10

After my Application have been refused by the play Store I have to remove MANAGE_EXTERNAL_STORAGE to the manifest. This authorisation is only for app like antivirus or file manager.

I need to get a file like this :

File file = new File("/sdcard/Download/Myfile.pdf");

This actually produce the following error on android 11 :

FILE NOT FOUND/sdcard/Download/GE-ACTIONS-03.pdf: open failed: EACCES (Permission denied)

Are there a possibility to get The File in this way ?

I need this file to create a fileInputStream like this :

fileInputStream = new FileInputStream(file);

(I already read other answer on stack overflow but they all use MANAGE_EXTERNAL_STORAGE.)

CodePudding user response:

well, question in title is pretty clear, same as answer: you can't. these all permissions and restrictions are created for purpose (securing user), not for breaking/ommiting them

currently on newest system versions you have to use Scoped Storage and you can freely store files onle there. afaik you can get access to Download folder (and other media ones) using Media Store API, but on devices with Scoped Storage your app will see only own files stored in this folder (downloaded by itself, not by another apps)

CodePudding user response:

You should first use File.exists() and then File.canRead().

The latter will return false if your app did not create the file.

If your app did not create the file let the user pick the file with ACTION_OPEN_DOCUMENT

  •  Tags:  
  • Related