卡上打开文件夹 [英] Open folder on card
问题描述
我认为这是很简单的东西,但它给了我比整个应用程序的其他部分更多的工作。
I thought this was something really simple, but it's giving me more work than the rest of the whole app.
我只想要一个按钮,打开我的应用程序的下载文件文件夹。就这样。没有文件选择器,没有什么复杂的。所有按钮所要做的就是打开默认的应用程序文件夹(或打开应用程序选择器如果没有默认值)。
I just want a button to open the "Downloaded Files" folder of my app. That's all. No file picker, nothing complicated. All the button has to do is open a folder with the default app (or open the app chooser if there's no default).
我尝试了不同的解决方案,我在这里看到的计算器,但似乎没有为我工作。
I tried different solutions I saw here on StackOverflow, but nothing seems to work for me.
实施例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系统,这将打开奇巧文件选择器,甚至不希望我的文件夹中打开...这似乎是默认为卡根。但我敢肯定的文件夹存在并且报错路径意图确实是正确的。
On my Android 4.4, this opens the KitKat file picker, and doesn't even open in the folder I want... it seems to be defaulting to the card root. But I'm sure the folder exists and the path being given to the Intent is indeed correct.
例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。
This one opens some blank activity with a popup saying: "Error occurred when getting file Content: MyDownloadedFiles".
我怎样才能让我的应用程序只需一个快捷方式到它把内容到?一个文件夹
推荐答案
哇..最后!很多事情我试过之后,只有它的工作方式是,首先包裹URI字符串转换成文件,然后做一个Uri.fromFile:
wow.. Finally!! After many things I tried, the only way it worked was by wrapping the URI string into a File first, and then do a Uri.fromFile:
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/MyDownloadedFiles/");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "*/*");
startActivity(Intent.createChooser(intent, getString(R.string.action_downloaded)));
这篇关于卡上打开文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!