import java.io.File; import java.io.IOException; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.webkit.MimeTypeMap; public class FileOpener { public static void openFile(Context context, File file) throws IOException { Uri uri = Uri.fromFile(file); MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); String fileMimeType = mimeTypeMap.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(uri.toString())); Intent intent = new Intent(Intent.ACTION_VIEW); if (fileMimeType != null && fileMimeType.length() > 0) { intent.setDataAndType(uri, fileMimeType); } else { intent.setDataAndType(uri, "*/*"); } context.startActivity(intent); } }
原文:http://my.oschina.net/oppo4545/blog/319016