How to get media file path selected from gallery for an API level 18+ app?

134 views Asked by At

I am using following code to get an image from gallery for API level 18+.

public Bitmap getBitmapFromUri() throws IOException {
    ParcelFileDescriptor parcelFileDescriptor =
            context.getContentResolver().openFileDescriptor(uri, "r");
    FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
    options.inSampleSize = 4;
    Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
    parcelFileDescriptor.close();
    return image;
}

Can someone let me know how can I get the file path as I need to store that for later usage.

I have gone through many solutions on the similar lines as given in the following thread(link) but none of them work for API 18+.

Get/pick an image from Android's built-in Gallery app programmatically

I have tried my best to find the solution but just in case I have missed it then please share the thread URL.

0

There are 0 answers