Open specific path using Storage access framework

2019-08-26 22:25发布

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条回答
可以哭但决不认输i
2楼-- · 2019-08-26 22:42

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);
查看更多
登录 后发表回答