Android的:如何通过意图打开一个特定的文件夹,并显示其在一个文件浏览器中的内容? [英] Android: How to open a specific folder via Intent and show its content in a file browser?

查看:3649
本文介绍了Android的:如何通过意图打开一个特定的文件夹,并显示其在一个文件浏览器中的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这将是容易的,但事实证明可惜这不是。

我有什么:

我有一个叫上我的外部存储MyFolder的文件夹(没有SD卡,因为它是一台Nexus 4,但应该不是问题)。该文件夹包含一些 *。CSV 文件。

我要什么:

我想写一个方法,执行以下操作:显示各种应用程序(文件浏览器)从中我可以选择一个(见图片)。当我点击它,选择的文件浏览器应该启动并告诉我MyFolder中的内容。没有更多的也不少。

我的问题:

到底如何做呢?我想我是相当接近与以下code,但无论我做什么 - 我敢肯定,一定有什么东西,我没有得到正确的,但 - 它总是从外部存储仅打开主文件夹

 公共无效openFolder()
{
档案文件=新的文件(Environment.getExternalStorageDirectory()
    MyFolder中);

Log.d(路径,file.toString());

意向意图=新的意图(Intent.ACTION_GET_CONTENT);
intent.setDataAndType(Uri.fromFile(文件),* / *);
startActivity(意向);
}
 

解决方案

我终于得到了它的工作。只有这样,一些应用程序显示在选择器(谷歌驱动器,Dropbox的,根浏览器和固体资源管理器)。它的正常工作与两名探险而与谷歌驱动器和Dropbox(我猜是因为他们不能访问外部存储)。另一种MIME类型,比如* / *也是可以的。

 公共无效openFolder()
{
意向意图=新的意图(Intent.ACTION_GET_CONTENT);
开放的我们的uri = Uri.parse(Environment.getExternalStorageDirectory()。getPath()
    +/ MyFolder的/);
intent.setDataAndType(URI,文/ CSV);
startActivity(Intent.createChooser(意向,打开文件夹));
}
 

I thought this would be easy but as it turns out unfortunately it's not.

What I have:

I have a folder called "myFolder" on my external storage (not sd card because it's a Nexus 4, but that should not be the problem). The folder contains some *.csv files.

What I want:

I want to write a method which does the following: Show a variety of apps (file browsers) from which I can pick one (see picture). After I click on it, the selected file browser should start and show me the content of "myFolder". No more no less.

My question:

How exactly do I do that? I think I came quite close with the following code, but no matter what I do - and I'm certain that there must be something I didn't get right yet - it always opens only the main folder from the external storage.

public void openFolder()
{
File file = new File(Environment.getExternalStorageDirectory(),
    "myFolder");

Log.d("path", file.toString());

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setDataAndType(Uri.fromFile(file), "*/*");
startActivity(intent);
}

解决方案

I finally got it working. This way only a few apps are shown by the chooser (Google Drive, Dropbox, Root Explorer and Solid Explorer). It's working fine with the two explorers but not with Google Drive and Dropbox (I guess because they cannot access the external storage). An other MIME type like "*/*" is also possible.

public void openFolder()
{
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
    + "/myFolder/");
intent.setDataAndType(uri, "text/csv");
startActivity(Intent.createChooser(intent, "Open folder"));
}

这篇关于Android的:如何通过意图打开一个特定的文件夹,并显示其在一个文件浏览器中的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆