0

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.

David Ferreira
  • 1,233
  • 17
  • 24
  • see if the answers to this similar question help: https://stackoverflow.com/questions/13080540/what-causes-androids-contentresolver-query-to-return-null – TheAtomicOption Oct 11 '17 at 20:27

1 Answers1

0

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.

David Ferreira
  • 1,233
  • 17
  • 24