Android调用本机程序执行文件的方法

有时需要用运行文件,如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);
	}

 

你可能感兴趣的:(android)