Skip to content

Instantly share code, notes, and snippets.

@OnlyInAmerica
Last active January 24, 2022 18:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OnlyInAmerica/3dadd26fddb29c0f777d to your computer and use it in GitHub Desktop.
Save OnlyInAmerica/3dadd26fddb29c0f777d to your computer and use it in GitHub Desktop.
Get Thumbnail from Android Storage Access Framework file using MediaStore
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);
}
@CodeWithOz
Copy link

Do you know how to get the file path of the resulting thumbnail Bitmap object?

@OnlyInAmerica
Copy link
Author

OnlyInAmerica commented Apr 22, 2021 via email

@alifhasnain
Copy link

Not working on Pie devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment