有时需要用运行文件,如MP3,MP4等,可用下面的方法调用本机程序来执行它
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file://"+info.getFile().getPath());
String type = null;
try {
type = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(info.getFile().getCanonicalPath()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(type!=null){
//intent.setType(type);
intent.setDataAndType(uri, type);
startActivityForResult(intent, 1);
}
本文介绍了一种在应用程序中通过Intent调用本地文件的方法,例如MP3或MP4文件。通过使用MimeTypeMap获取文件类型,并设置Intent以正确打开对应类型的文件。
6万+

被折叠的 条评论
为什么被折叠?



