Android中目录的MIME类型
我想知道我是否可以开始使用文件浏览器查看目录(如果设备上安装了文件浏览器),这样我就可以打开如下文件夹:Android中目录的MIME类型,android,mime-types,android-intent,Android,Mime Types,Android Intent,我想知道我是否可以开始使用文件浏览器查看目录(如果设备上安装了文件浏览器),这样我就可以打开如下文件夹: Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse("file:///sdcard/MyFolder"); intent.setDataAndType(uri, "MIME TYPE FOR FOLDERS"); startActivity(intent); 具有供应商mime类型,可将AndExplore
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/MyFolder");
intent.setDataAndType(uri, "MIME TYPE FOR FOLDERS");
startActivity(intent);
具有供应商mime类型,可将AndExplorer用作文件选择器:
vnd.android.cursor.dir/lysesoft.andexplorer.director
vnd.android.cursor.dir/lysesoft.andexplorer.file
- vnd.android.cursor.item/file
我想这就是为什么存在这样的网站,开发者可以共享一些标准,或者至少发布一些标准的应用程序功能。根据一些谷歌搜索,字符串“inode/directory”和“x-directory/normal”似乎是基于Unix的系统中预先存在的MIME类型,但我手机上的任何东西都不知道这一点,所以在寻找vnd.android.cursor.item/directory之前,我可能会检查并提供这些信息,至少它具有不绑定到特定应用程序的价值 我不愿意使用特定于应用程序的类型
(我刚刚发现ES使用的“resource/folder”似乎也是独立于应用程序的;太糟糕了,没有办法告诉Android这些类型都是等效的。)因为作为目录的文件似乎没有标准的mime类型,我将我的文件资源管理器编码为过滤没有mime类型的意图。只需将数据设置为文件夹的Uri。这还将intent方案设置为“file”,这是我的intent过滤器所必需的
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/MyFolder");
intent.setData(uri);
startActivity(intent);
此意图将启动以下应用程序:
根据官方说法,它是vnd.android.cursor.dir/*这是一个古老的问题,但我注意到在任何答案中都没有正确指定目录MimeType。我在SAF(存储访问框架)的Google代码示例中发现了这一点: 这是哪个字符串:
vnd.android.document/directory
因此,对于最初的问题:
Uri uri = Uri.parse(getFilesDir().getPath());
int OPEN_REQUEST = 1337;
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setDataAndType(uri, DocumentsContract.Document.MIME_TYPE_DIR);
startActivityForResult(intent, OPEN_REQUEST);
但是存储访问框架将为您浏览目录。因此,您可能只需要执行以下操作:
int OPEN_REQUEST = 1337;
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, OPEN_REQUEST);
据我所知,文件夹没有MIME类型。嗯。。有关于如何使用已安装的文件浏览器打开文件夹的线索吗?谢谢,但如果用户的手机没有该应用程序,它将失败。我试过我的手机,它只是显示驱动器PDF查看器和SQLiteViewer,看起来像是Cyanogen文件管理器(com.cyanogenmod.filemanager)使用了它。我想MIME类型是动作无关的。我试过了,应用程序强制关闭,这是错误日志:“java.lang.RuntimeException:无法启动活动组件信息”{com.android.gallery3d/com.android.gallery3d.app.GalleryActivity}:java.lang.ClassCastException:com.android.gallery3d.data.UriImage无法转换为com.android.gallery3d.data.MediaSet“我使用的是CyanogenMod 12.1-YOG4PAS1N0,android版本:5.1.1这对我很有用。此外,我还可以使用vnd.android.cursor.dir/image将目录打开到gallery应用程序中,而不是让用户在gallery |文件浏览器|等之间进行选择。在虚拟Nexus 10上运行android KitKat。记录代码是:
final file dir=getaveImageDir();final Intent Intent Intent=new Intent(Intent.ACTION_VIEW);Intent.setDataAndType(Uri.fromFile(dir),“vnd.android.cursor.dir/image”);startActivity(Intent);
没有理由为此指定特定的应用程序。为了获得更好、更通用的解决方案
int OPEN_REQUEST = 1337;
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, OPEN_REQUEST);