Last active
January 24, 2022 18:18
-
-
Save OnlyInAmerica/3dadd26fddb29c0f777d to your computer and use it in GitHub Desktop.
Get Thumbnail from Android Storage Access Framework file using MediaStore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (/* your media path came from Android Storage Access Framework on 4.4+ */) { | |
//mediaFile.getPath() = "content://com.android.providers.media.documents/document/video:183" | |
long videoId = Long.parseLong(Uri.parse(mediaFile.getPath()).getLastPathSegment().split(":")[1]); | |
Bitmap thumbnail = MediaStore.Video.Thumbnails.getThumbnail(mContext.getContentResolver(), | |
videoId, | |
MediaStore.Images.Thumbnails.MINI_KIND, // 512 x 384 | |
//MediaStore.Images.Thumbnails.MICRO_KIND, // 96 x 96 | |
null)); // BitmapFactory.Options | |
ivThumbnail.setImageBitmap(thumbnail); | |
} |
I’m a bit rusty on my Android knowledge now, but I believe the point of
ContentResolver is to abstract away file paths.
If you need the thumbnail as a file you’d probably have to write the bitmap
to a file yourself.
…On Thu, Apr 22, 2021 at 9:47 AM Uche Ozoemena ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Do you know how to get the file path of the resulting thumbnail Bitmap
object?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/3dadd26fddb29c0f777d#gistcomment-3716174>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADP6DWJZZLLRRRZX54D7HDTKBHJ5ANCNFSM43M3DFDA>
.
Not working on Pie devices.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you know how to get the file path of the resulting thumbnail
Bitmap
object?