Open specific path using Storage access framework

2019-08-26 21:55发布

问题:

I am able to write the text files by opening the Files app using the intent. But when I open the Files app through intent it is opening Downloads path instead I would like to open a specific path. Is that possible ?

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TITLE, fileName);
startActivityForResult(intent, CREATE_REQUEST_CODE);

I would like to launch the Files app using Intent and it should open specific path. I have tried intent.setDataAndType by passing the Uri, but it is not working.

回答1:

in order to indicate the initial location of documents navigator you should add this to your intent :

intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, your_initial_uri);

like this :

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, your_initial_uri);
intent.putExtra(Intent.EXTRA_TITLE, fileName);
startActivityForResult(intent, CREATE_REQUEST_CODE);