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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not working on Pie devices.