Uri when select any image or video -> "content://media/external/file/34"
Asked
Active
Viewed 566 times
0
-
This is a duplicate of [link](https://stackoverflow.com/questions/8589645/how-to-determine-mime-type-of-file-in-android) – Ebenezer Nikabou Jul 19 '21 at 12:17
-
2While that linked-to question has lots of bad answers, [this answer](https://stackoverflow.com/a/31691791/115145) is pretty good. – CommonsWare Jul 19 '21 at 12:22
-
Thank you for your answer but I need Mime type from arraylist
. – Monali0521 Jul 19 '21 at 13:04
1 Answers
1
Please try with below line of code
Uri selectedUri;
String fileextension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString());
String mimetype= MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileextension);
If(mimetype=="image/jpeg")
-
-
If you are getting the list of video/image in this way using the ccontent resolver and cursor then please try below way private val PROJECTION = arrayOf(MediaStore.MediaColumns.MIME_TYPE) String pictureType = cursor.getString(cursor.getColumnIndexOrThrow(PROJECTION[0])) IF NOT then try to check when you added or get in list for every item in list – gpuser Jul 19 '21 at 13:09
-