Skip to content

Instantly share code, notes, and snippets.

@btipling
Created January 3, 2012 08:33
Show Gist options
  • Save btipling/1554096 to your computer and use it in GitHub Desktop.
Save btipling/1554096 to your computer and use it in GitHub Desktop.
Opening a file with default app in android
try {
URL url = file.toURI().toURL();
String ext = MimeTypeMap.getFileExtensionFromUrl(url.toString());
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), map.getMimeTypeFromExtension(ext)));
startActivity(intent);
} catch (Exception e) {
Log.e(TAG, "Malformed URL: " + e, e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment