0

I am trying to list non-media content from Download folder using SAF.

Sample Code:

public void openDirectory(Uri uriToLoad) {
    // Choose a directory using the system's file picker.
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);

    // Provide read access to files and sub-directories in the user-selected
    // directory.
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    // Optionally, specify a URI for the directory that should be opened in
    // the system file picker when it loads.
    intent.putExtra(EXTRA_INITIAL_URI, uriToLoad);

    startActivityForResult(intent, 500);
}

But when i open the Download Folder using SAF i see the "use this folder" button is disable.

I also noticed from the android documents they introduced new MediaStore.Download

https://developer.android.com/reference/android/provider/MediaStore.Downloads

i tried to use but i see the cursor count is zero. When should we use the above api ?

Abdul
  • 79
  • 1
  • 6

1 Answers1

2
But when i open the Download Folder using SAF i see the "use this folder" button is disable.

It's because in Android-11, accessing Download folder through ACTION_OPEN_DOCUMENT_TREE is restricted.

You can no longer use the ACTION_OPEN_DOCUMENT_TREE intent action to request access to the following directories:

The root directory of the internal storage volume.
The root directory of each SD card volume that the device manufacturer considers to be reliable, regardless of whether the card is emulated or removable. A reliable volume is one that an app can successfully access most of the time.
The Download directory.

Reference https://developer.android.com/about/versions/11/privacy/storage#file-directory-restrictions

Spring Breaker
  • 8,233
  • 3
  • 36
  • 60
  • Is there an alternative to `ACTION_OPEN_DOCUMENT_TREE` If I want to allow my users to use folders and look at content of files in those folder, including the `Download` folder, but my app is not a file explorer? I already have `ACTION_OPEN_DOCUMENT` to show a picker but my users are picky as to how they want to see the files listed so I have my own explorer like activity to show them files inside a folder as well. – casolorz Sep 05 '21 at 01:45