【发布时间】:2014-07-21 08:04:00
【问题描述】:
我认为这是非常简单的事情,但它比整个应用程序的其余部分给了我更多的工作。
我只想要一个按钮来打开我的应用程序的“已下载文件”文件夹。就这样。没有文件选择器,没什么复杂的。按钮所要做的就是打开一个包含默认应用程序的文件夹(如果没有默认应用程序,则打开应用程序选择器)。
我尝试了我在 StackOverflow 上看到的不同解决方案,但似乎没有什么对我有用。
示例 1:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/MyDownloadedFiles/");
intent.setDataAndType(uri, "text/plain");
startActivity(Intent.createChooser(intent, getString(R.string.action_downloaded)));
在我的 Android 4.4 上,这会打开 KitKat 文件选择器,甚至没有在我想要的文件夹中打开......它似乎默认为卡根。但我确定该文件夹存在并且提供给 Intent 的路径确实是正确的。
示例 2:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/MyDownloadedFiles/");
intent.setDataAndType(uri, "text/plain");
startActivity(Intent.createChooser(intent, getString(R.string.action_downloaded)));
这会打开一些空白活动,并弹出一个提示:“获取文件内容时发生错误:MyDownloadedFiles”。
我怎样才能让我的应用只拥有一个快捷方式,指向将内容放入的文件夹?
【问题讨论】:
标签: android android-intent android-sdcard