Android Code Snippet To get bitmaps of thumbnails of your videos or images on device with MediaStore

It depends on what MediaStore has indexed

You can further refine the search by modifying the query

You can also check the images by asking "android.provider.MediaStore.Images$Media" and "android.provider.MediaStore.Images.Thumbnails", modifying with "mime_type LIKE 'image/%'"

Sub GetBitmapsOfVideoThumbnails

    Dim MediaStore As JavaObject
    Dim uri As Object
    Dim MediaStore_Video_Thumbnails As JavaObject

    uri = MediaStore.GetField("EXTERNAL_CONTENT_URI")        'content://media/external/images/media for images, content://media/external/video/media fo videos

    Dim cr As ContentResolver        'ContentResolver library

    Dim thumbCursor As Cursor    'SQL lib
    thumbCursor = cr.Query(uri, Null, "mime_type LIKE 'video/%'", Null, Null)            'LIMIT not work on android 11+
    Log("thumbCursor.RowCount = " & thumbCursor.RowCount)

    If thumbCursor <> Null And thumbCursor.RowCount > 0 Then
        For i = 0 To thumbCursor.RowCount - 1
            thumbCursor.Position = i
            Private videoId As Long = thumbCursor.GetString("_id")
            LogColor(uri & "/" & videoId, Colors.Blue)

            'Option with MediaStore.Video.Thumbnails.getThumbnail(...):
            Dim r As Reflector
            Dim cres As Object
            r.Target = r.GetContext
            cres = r.RunMethod("getContentResolver")

            Private bm As Bitmap = MediaStore_Video_Thumbnails.RunMethod("getThumbnail", Array As Object(cres, videoId, 3, Null))    '3 = MICRO_KIND     1 = MINI_KIND
            Log(bm.Width & " x " & bm.Height)

            'Option with ContentResolver.loadThumbnail(...):
            Dim SizeObj As JavaObject
            Dim size As JavaObject = SizeObj.InitializeNewInstance("android.util.Size", Array As Object(96, 96))

            Dim uri2 As JavaObject
            Dim u As JavaObject = uri2.InitializeStatic("").RunMethod("parse", Array As String(uri & "/" & videoId))
            LogColor(u, Colors.Magenta)
            Dim csign As JavaObject
            Dim cs As JavaObject = csign.InitializeNewInstance("android.os.CancellationSignal", Null)

            Dim ctxt As JavaObject
            Dim ContentResolver As JavaObject = ctxt.InitializeContext.RunMethodJO("getContentResolver", Null)    '

            Dim Thumbnail As Bitmap
            Thumbnail = ContentResolver.RunMethod("loadThumbnail", Array(u, size, csign))
            Log(Thumbnail.Width & " xx " & Thumbnail.Height)

    End If
End Sub
Last edited: