I'm doing a method to get all the images and videos from a specific path and then, get the thumbnails of these and putting them in another path. I got the following:
public void getThumbnails(String persistentDataPath) {
// 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,
};
// 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 = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).toString() + "/Azlo/");
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(
queryUri,
projection,
selection,
null, // Selection args (none).
MediaStore.Files.FileColumns.DATE_ADDED + " DESC" // Sort order.
);
Bitmap bitmap;
//Now i will traverse the cursor and get the bitmap thumbnail for every item
for( int i = 0 ; i < cursor.getCount(); i++) {
cursor.moveToPosition(i);
long elementId = cursor.getLong(0);
// code to get the thumbail using the item id
// using method MediaStorage.Video.Thumbnails.getThumbnail
// and MediaStorage.Image.Thumbnails.getThumbnail
}
}
The problem is that the query its not working and its returning null i don't know why. The path i used returns "/storage/emulated/0/Movies/AzloAR" and there are .mp4 and .jpg files inside that folder.
Can you help me please? :)
Another question, how can i know (with a conditional) if the item of the cursor is a video or an image.