Android Developer
Android Developer

Reputation: 9665

Get all video files from a programmatically created folder

I am using below code to fetch all videos from a specific folder.

 String selection=MediaStore.Video.Media.DATA +" like?";
 String[] selectionArgs = new String[]{folderPath};
 return new CursorLoader(this, MediaStore.Video.Media.EXTERNAL_CONTENT_URI, COLUMNS_OF_INTEREST, selection, selectionArgs,
                MediaStore.Video.Media.DATE_ADDED + " ASC");

But this doesn't work for programmatically created folders.How can I fetch all video files from a programmatically created folder?

Upvotes: 0

Views: 3126

Answers (1)

varunkr
varunkr

Reputation: 5552

This is probably happening since your device needs to scan for the changed files. You can do it like this.

 MediaScannerConnection.scanFile(this,
          new String[] { file.toString() }, null,
          new MediaScannerConnection.OnScanCompletedListener() {
      public void onScanCompleted(String path, Uri uri) {
          //Do something
      }
 });

Upvotes: 1

Related Questions