Unn*_*ati 5 android file android-intent mime-types
我想打开一个文件android.我想要做的是如果文件是类型Image然后我想打开Intent Chooser其中包含可以查看图像的应用程序,如果它是视频类型,然后打开与可以查看视频的应用程序的Intent Chooser.我怎样才能实现这一目标?
Unn*_*ati 13
我找到了解决方案.我在这里粘贴它,所以它可以帮助其他用户.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(path);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext = file.getName().substring(file.getName().indexOf(".") + 1);
String type = mime.getMimeTypeFromExtension(ext);
intent.setDataAndType(Uri.fromFile(file), type);
context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)