Oreo - 阻止 ACTION_GET_CONTENT 使用内置文件应用
Oreo - Prevent ACTION_GET_CONTENT from using built-in Files app
我的应用程序从用户选择的文件中读取信息(然后用它做一些奇怪而美妙的事情!)。为简单起见,"file explorer" 应用程序指向一个特定的起始目录(应用程序之前存储此类文件的位置)。
这很好用,除了在我的 Oreo phone (Nexus5) 上,内置的 Google 应用程序文件始终启动,即使在存在备用文件管理器应用程序的情况下。 文件不响应意图的 uri;因此,用户每次都必须导航到该目录。这是相关代码:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
+ "/Documents/" + getResources().getString(R.string.app_name));
intent.setDataAndType(uri, "text/plain");
try {
startActivityForResult(Intent.createChooser(intent, "Open folder"), request_code);
}
catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(this, "Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
我四处寻找解决方案,但无济于事。如何解决?
我感兴趣的选项:
- 禁用文件
- 防止 Intent 使用文件
- 与文件交谈,以便它打开指定的目录
- 强制 Intent 使用不同的文件资源管理器应用程序(这是应用程序的偏好)
- 不涉及使用文件选择器库的任何其他解决方案
To make this simple, the "file explorer" app is pointed to a specific starting directory (where the app had previously stored such files).
没有 Intent
操作,抱歉。
This works fine, except on my Oreo phone (Nexus5)
它将在数亿台设备上失败。 ACTION_GET_CONTENT
不带 Uri
。引用 the documentation:
Note that no URI is supplied in the intent, as there are no constraints on where the returned data originally comes from.
另请注意,ACTION_GET_CONTENT
不一定要涉及文件浏览器,设备也不一定要有文件浏览器应用程序。
Files does not respond to the intent's uri;
ACTION_GET_CONTENT
实现不应响应 Uri
。
Any other solution that does not involve the use of a file chooser library
编写您自己的文件选择器UI。或者,从您的应用中删除该功能。
我的应用程序从用户选择的文件中读取信息(然后用它做一些奇怪而美妙的事情!)。为简单起见,"file explorer" 应用程序指向一个特定的起始目录(应用程序之前存储此类文件的位置)。
这很好用,除了在我的 Oreo phone (Nexus5) 上,内置的 Google 应用程序文件始终启动,即使在存在备用文件管理器应用程序的情况下。 文件不响应意图的 uri;因此,用户每次都必须导航到该目录。这是相关代码:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
+ "/Documents/" + getResources().getString(R.string.app_name));
intent.setDataAndType(uri, "text/plain");
try {
startActivityForResult(Intent.createChooser(intent, "Open folder"), request_code);
}
catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(this, "Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
我四处寻找解决方案,但无济于事。如何解决?
我感兴趣的选项:
- 禁用文件
- 防止 Intent 使用文件
- 与文件交谈,以便它打开指定的目录
- 强制 Intent 使用不同的文件资源管理器应用程序(这是应用程序的偏好)
- 不涉及使用文件选择器库的任何其他解决方案
To make this simple, the "file explorer" app is pointed to a specific starting directory (where the app had previously stored such files).
没有 Intent
操作,抱歉。
This works fine, except on my Oreo phone (Nexus5)
它将在数亿台设备上失败。 ACTION_GET_CONTENT
不带 Uri
。引用 the documentation:
Note that no URI is supplied in the intent, as there are no constraints on where the returned data originally comes from.
另请注意,ACTION_GET_CONTENT
不一定要涉及文件浏览器,设备也不一定要有文件浏览器应用程序。
Files does not respond to the intent's uri;
ACTION_GET_CONTENT
实现不应响应 Uri
。
Any other solution that does not involve the use of a file chooser library
编写您自己的文件选择器UI。或者,从您的应用中删除该功能。