kao*_*ick 63 directory android android-intent android-sdcard
我认为这很容易但事实证明不幸的是.
是)我有的:
我的外部存储器上有一个名为"myFolder"的文件夹(不是SD卡,因为它是Nexus 4,但这应该不是问题).该文件夹包含一些*.csv文件.
我想要的是:
我想写一个方法,它执行以下操作:显示各种应用程序(文件浏览器),我可以从中选择一个(见图片).单击它后,所选的文件浏览器应该启动并显示"myFolder"的内容.不多也不少.

我的问题:
我到底该怎么做?我想我接下来的代码非常接近,但无论我做什么 - 而且我确定必须有一些我还没有做到的事情 - 它始终只打开来自外部存储器的主文件夹.
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);
}
Run Code Online (Sandbox Code Playgroud)
Aya*_*fov 60
这应该工作:
Uri selectedUri = Uri.parse(Environment.getExternalStorageDirectory() + "/myFolder/");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(selectedUri, "resource/folder");
if (intent.resolveActivityInfo(getPackageManager(), 0) != null)
{
startActivity(intent);
}
else
{
// if you reach this place, it means there is no any file
// explorer app installed on your device
}
Run Code Online (Sandbox Code Playgroud)
请确保您的设备上安装了任何文件资源管理器应用.
编辑:从评论中添加了shantanu的推荐.
图书馆:如果当前的解决方案对您没有帮助,您还可以查看这些文件/目录选择器库https://android-arsenal.com/tag/35.
kao*_*ick 38
我终于搞定了.这样,选择器(Google Drive,Dropbox,Root Explorer和Solid Explorer)只显示几个应用程序.它与两个浏览器一起正常工作,但不适用于Google Drive和Dropbox(我猜因为它们无法访问外部存储).另一种MIME类型"*/*"也是可能的.
public void openFolder(){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
+ File.separator + "myFolder" + File.separator);
intent.setDataAndType(uri, "text/csv");
startActivity(Intent.createChooser(intent, "Open folder"));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
107281 次 |
| 最近记录: |