Reputation: 39
Bitmap miniThumb = MediaStore.Images.Thumbnails.getThumbnail(cr,id,MediaStore.Images.Thumbnails.MINI_KIND);
Upvotes: 3
Views: 2719
Reputation: 5491
You can use it by checking the SDK version first.
If you queried for media, the mediaUri
will be constructed by appending the media ID to the content URI, e.g. mediaUri = ContentUris.withAppendedId(imagesContentUri, id)
val thumbnail = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val cs = CancellationSignal()
context.contentResolver.loadThumbnail(mediaUri, Size(100, 100), cs)
} else {
MediaStore.Images.Thumbnails.getThumbnail(context.contentResolver, id, MediaStore.Images.Thumbnails.MINI_KIND, null)
}
Upvotes: 2
Reputation: 219
MediaMetaDataRetriever mmr = new MediaMetaDataRetriever();
mmr.setDataSource("path of your file"); //===========Other Options also available
byte[] data = mmr.getEmbededPicture();
if(data!=null){
//========Create Bitmap with byte array======//
}else{
//========Do your code if media has no image====//
}
Upvotes: 0