使用存储访问框架打开特定目录 [英] Open Specific Directory Using Storage Access Framework
问题描述
我目前可以通过使用以下代码打开Lollipop文件选择器来获取文件URI:
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);
文件选择器将在Internal Storage的根目录或我打开的最后一个目录中打开. 如何使文件选择器显示特定目录的内容?例如,我可能希望文件选择器在启动后显示下载"文件夹的内容,如下图所示.
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.
推荐答案
使用 Environment 类,该类具有类似getExternalStorageDirectory()
或getDataDirectory()
的方法
https://developer.android.com/reference/android/os/Environment. html .
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";
这篇关于使用存储访问框架打开特定目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!