1

In my app I created a file picker that returns a list of uris like the ones below:

[content://media/external/file/300725, content://media/external/file/299993, content://media/external/file/299986]

Is there any way to know if each of these files is an image or a video?

Vitor Ferreira
  • 1,075
  • 1
  • 14
  • 28
  • You can check the mime type from the Uri, then use getExtensionFromMimeType method to get the file extention – Walid Jul 06 '20 at 13:54

1 Answers1

3

One way to do so is following this SO post

In short to find an image:

public static boolean isImageFile(String path) {
String mimeType = URLConnection.guessContentTypeFromName(path);
return mimeType != null && mimeType.startsWith("image"); }

To find a video:

public static boolean isVideoFile(String path) {
String mimeType = URLConnection.guessContentTypeFromName(path);
return mimeType != null && mimeType.startsWith("video");}
codearn19
  • 161
  • 10