
Get Extension From URI android
I have a Task to upload file to S3 using presigned URL, I create an atomic name from current date and want extension to append it and send it to S3 but faced problems to get extensions and here will share journey
Let’s start
we can get it in two ways
- Get Path and got extension as it last part.
- Get MIME Type
First way: Path

this will return path and use this filePath.substring(filePath.lastIndexOf(".") + 1);
but previous call may return null in case of file is stored in google photos (i.e. not locally on phone) so we must download it into device (which add more space on device) and then get path


Second: MIME Type
this way is guarantee to get extension but as Type which treat JPEG/JPG
as JPEG

I hope this help you when dealing with this task.