Access Ordered Images and Video in Same Cursor

Access ordered images and video in same Cursor

After lots of research and playing around with source code, I'm finally a bit more familiar with the Android filesystem. To get a single Cursor which can access information about both Images and Video I used the following:

// Get relevant columns for use later.
String[] projection = {
MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DATA,
MediaStore.Files.FileColumns.DATE_ADDED,
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.MIME_TYPE,
MediaStore.Files.FileColumns.TITLE
};

// Return only video and image metadata.
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE
+ " OR "
+ MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;

Uri queryUri = MediaStore.Files.getContentUri("external");

CursorLoader cursorLoader = new CursorLoader(
this,
queryUri,
projection,
selection,
null, // Selection args (none).
MediaStore.Files.FileColumns.DATE_ADDED + " DESC" // Sort order.
);

Cursor cursor = cursorLoader.loadInBackground();

Android How can I using Cursor get image and video thumbnails in my direct path both?

I found the answer.

We should inverse the method.

We can find the real path. then to get the ID.

Through the ID to get the images and videos thumbnails.

To get the images and videos using a cursor can refer the articles.

Getting images thumbnails using below code:

 bitmap = MediaStore.Images.Thumbnails.getThumbnail(context
.getApplicationContext().getContentResolver(), item.getImgId(),
MediaStore.Images.Thumbnails.MICRO_KIND, null);

Getting video thumbnails using below code:

  bitmap = MediaStore.Video.Thumbnails.getThumbnail(context
.getApplicationContext().getContentResolver(), item.getImgId(),
MediaStore.Images.Thumbnails.MICRO_KIND, null);

How to get images and videos thumbnails from a path, not working

The URI i was sending to the query was invalidad. The query needs a content:// style URI and this is generated by using methods and fields of MediaStore classes, like MediaStore.Files.getContentUri(String volumeName) or MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI.



Related Topics



Leave a reply



Submit