I am using the following code to get files from gallery. The file that i retrieve is either image file, video file or an audio file based on user selection.
Now i am displaying the file retrieve from the gallery inside a list view. But i am not able to distinguish that the file selected by the user is image file(i.e .jpg / .png) or its an video file or an audio file.
By getting the extension and checking it in the if else condition its possible i know. But i want to know its there any possible way of doing this
Code used to get image from Gallery is
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(intent, GET_VIDEO_AUDIO);
fileTransferDialog.dismiss();
Just check the MIME type of the file. Have a look at this
https://stackoverflow.com/a/13889946/1570662
This might help
private static String getMimeType(String fileUrl) {
String extension = MimeTypeMap.getFileExtensionFromUrl(fileUrl);
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With