我想在 android
中打开一个文件。我想要做的是,如果文件是 Image
类型,那么我想打开 Intent Chooser
,其中包含可以查看图像的应用程序,如果它是视频类型,然后使用可以查看视频的应用程序打开 Intent Chooser。我怎样才能做到这一点?
最佳答案
我找到了解决办法。我将它粘贴在这里,以便它可以帮助其他用户。
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().lastIndexOf(".") + 1);
String type = mime.getMimeTypeFromExtension(ext);
intent.setDataAndType(Uri.fromFile(file), type);
context.startActivity(intent);
关于android - 自动打开 Android 文件的 Intent Chooser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23148966/