Pages

Tuesday 22 December 2015

Android get mime type of file or url

Use following function to get MIME Type of file. pass file path or any url

public static String getMimeType(String url) {
  try {
   String type = null;
   String extension = url.substring(url.lastIndexOf(".") + 1, url.length());
   Log.i("extension", "ext : " + extension);
   if (extension != null) {
    type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
   }
   return type;
  } catch (Exception e) {
   e.printStackTrace();
  }
  return null;
}

No comments :

Post a Comment