Open Specific Directory Using Storage Access Framework

时光怂恿深爱的人放手 提交于 2019-12-10 12:55:11

问题


I'm currently able to obtain a file URI by opening the Lollipop file picker using the code below:

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_OPEN_DOCUMENT_TREE);
            startActivity(intent);

The file picker opens either at the root of Internal Storage or the last directory that I opened. How can I make the file picker show the contents of a specific directory? For example, I might want the file picker to show the contents of the Download folder after launching like in the picture below.


回答1:


Use the Environment class which has methods like getExternalStorageDirectory() or getDataDirectory() https://developer.android.com/reference/android/os/Environment.html.

If the images are stored in a variable, grab them from that path:

private static final String fileName = Environment
            .getExternalStorageDirectory().getAbsolutePath()
            + "/pathToFile.jpg";


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

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