Open specific path using Storage access framework

爱⌒轻易说出口 提交于 2019-12-11 08:03:53

问题


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);


来源:https://stackoverflow.com/questions/52057001/open-specific-path-using-storage-access-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!