Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.File; import android.content.Intent; import android.net.Uri; import android.webkit.MimeTypeMap; public class Main { public static Intent getOpenFileIntent(File file) { if (file == null || !file.exists() || !file.isFile()) { return null; } String extension = MimeTypeMap.getFileExtensionFromUrl(file.getAbsolutePath()); String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (extension == null || mimeType == null) { return null; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.fromFile(file), mimeType); return intent; } }