Storage Access Framework as "Private" (Local only) Folder / File Picker?

My ultimate goal is to let the user select a folder to save the file to - a file is a video file that will be created at some point after the user has chosen a destination.
I just use the vault access map collector so they can choose where to save it.

First of all, is there a way to allow the user to only select the folder (not the file / filename)?
The best I can do right now is use an ACTION_CREATE_DOCUMENT

Intent to get the save location, however I don't want to specify the filename in the SAF collector (this will be done in the app) ...

Secondly, after reading the documentation for providing storage access and concatenating some bits from multiple code samples, I have a working DocumentProvider that almost does what I want - to allow the user to browse their external storage (SD cards) for a suitable places to save the video file - by adding my own root that points to Environment.getExternalStorageDirectory()

to the queryRoots () method.

However, I really want this to be my only root (at the moment when I also had a disk, boot, etc.).
Is it possible to remove / hide other roots so that it essentially becomes a file-based app picker?
Or even show only local storage (maybe a flag can help Root.FLAG_LOCAL_ONLY

)?

Thank!

+3


source to share


1 answer


API 21 supports Intent.ACTION_OPEN_DOCUMENT_TREE

. This allows you to select a location once, and then you can use the provided URI to manipulate its content.



private static final int LOCATION_CHOOSER_REQ_CODE = 4;

public void chooseLocation() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    startActivityForResult(intent, LOCATION_CHOOSER_REQ_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == LOCATION_CHOOSER_REQ_CODE && resultCode == Activity.RESULT_OK) {
        if (data != null) {
            Uri uri = data.getData();  // Use this URI to access files
        }
}

      

+1


source







All Articles