Android调用本机程序执行文件的方法
文章分类:移动开发
有时需要用运行文件,如MP3,MP4等,可用下面的方法调用本机程序来执行它
Java代码
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);
}
有时需要用运行文件,如MP3,MP4等,可用下面的方法调用本机程序来执行它
Java代码
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);
}
转载于:https://blog.51cto.com/zhaohaiyang/516958