---
title: "Android调用本机程序执行文件的方法"
author: "fonter"
date: "2010-06-24T13:18:08Z"
tags: []
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2010-06-24T13:18:08Z"
id: 698281
url: "https://fonter.iteye.com/blog/698281"
---

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