简体   繁体   English

如何在特定位置启动 Intent.ACTION_GET_CONTENT?

[英]How to start Intent.ACTION_GET_CONTENT in a specific location?

I am trying to open a directory for user to choose an excel document from it.我正在尝试打开一个目录供用户从中选择一个 excel 文档。 However, my file picker opens in the "recent" location.但是,我的文件选择器在“最近”位置打开。 Is there a way to start it from a specific directory using new versions of Android?有没有办法使用新版本的 Android 从特定目录启动它?

This is my code:这是我的代码:

 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                    Uri uri = Uri.parse(Environment.DIRECTORY_DOCUMENTS);
                    intent.setDataAndType(uri, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                    startActivity(Intent.createChooser(intent, "Open folder"));

You need to set EXTRA_INITIAL_URI:您需要设置 EXTRA_INITIAL_URI:

intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri)

Unfortunately, the Intent.ACTION_GET_CONTENT does not support opening in a specific location.不幸的是,Intent.ACTION_GET_CONTENT 不支持在特定位置打开。 The only way to choose a specific location is by using a third-party file picker library, such as FilePicker, aFileChooser, etc.选择特定位置的唯一方法是使用第三方文件选择器库,例如 FilePicker、aFileChooser 等。

You can use these libraries to create a custom file picker that opens in a specific location and allows the user to choose a file.您可以使用这些库来创建自定义文件选择器,该文件选择器在特定位置打开并允许用户选择文件。 Then, you can call the custom file picker in your code instead of using Intent.ACTION_GET_CONTENT.然后,您可以在代码中调用自定义文件选择器,而不是使用 Intent.ACTION_GET_CONTENT。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM