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
How to Convert Time to " Time Ago " in Android
How To: Install Plugin in Android Studio
How to Take Pictures from The Camera Without Preview When My App Starts
How to Fix Android Studio Getting Stuck Executing Gradle Tasks
Flutter Insecure Http Is Not Allowed by Platform
How to Create a Persistent Alarmmanager
Apply Two Different Font Styles to a Textview
Android: Radio Button in Custom List View
Package Signatures Do Not Match The Previously Installed Version
Onactivityresult Do Not Fire If Launch Mode of Activity Is Singleinstance
Zipalign - Command Not Found - MAC Terminal
How to Embed Vlc Media Player to My Android App
End Incoming Call Programmatically
Google Map for Android My Location Custom Button
Change Progressbar Color Through Code Only in Android
How to Store Files Generated from App in "Downloads" Folder of Android