Skip to content

Instantly share code, notes, and snippets.

@phajduk
Created June 4, 2014 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phajduk/2e28254c6e1ecad37785 to your computer and use it in GitHub Desktop.
Save phajduk/2e28254c6e1ecad37785 to your computer and use it in GitHub Desktop.
Getting mime type from file
Uri path = Uri.fromFile(file);
MimeTypeMap typeMap = MimeTypeMap.getSingleton();
String extension = MimeTypeMap.getFileExtensionFromUrl(path.toString()).toLowerCase();
if (extension.contains(".")) {
extension = extension.substring(extension.lastIndexOf("."));
}
String mimeType= typeMap.getMimeTypeFromExtension(extension);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment