Search code examples
androidandroid-intentvideo-recording

Recorded Video is not Visible in my other Activity untill I reboot my Tablet Asus Transformer


I have created a Project having many activities. One activity is to record the video, that is working fine. I can see the recorded video in my specified folder without restart my tablet.

But when I try to find all the videos in that folder in some other activity using query, see code below. Then I can't see my recorded video until I restart my tablet. I can see just old recorded videos before starting my tablet. I couldn't understand this strange behavior.

Can anyone put some light on this issue??

Thanks.

private void initVideosId() {    //  getting the videos id in Video Folder of SD Card
    try {
        // Here we set up a string array of the thumbnail ID column we want
        // to get back
        String[] proj = { _ID };
        //Querying for the videos in VideoGallery  folder of SD card
        // Now we create the cursor pointing to the external thumbnail store
        _cursor = managedQuery(_contentUri, proj, // Which columns to return
                MEDIA_DATA + " like ? ", // WHERE clause; which rows to
                                            // return (all rows)
                new String[] { "%VideoGallery%" }, // WHERE clause selection
                                            // arguments (none)
                null); // Order-by clause (ascending by name)
        int count = _cursor.getCount();
        // We now get the column index of the thumbnail id
        _columnIndex = _cursor.getColumnIndex(_ID);
        // initialize
        _videosId = new int[count];
        // move position to first element
        _cursor.moveToFirst();
        for (int i = 0; i < count; i++) {
            int id = _cursor.getInt(_columnIndex);
            //
            _videosId[i] = id;
            //
            _cursor.moveToNext();
            //
        }
    } catch (Exception ex) {
        showToast(ex.getMessage().toString());
    }

}

Solution

  • If you stored the file on external storage, you need to use MediaScannerConnection to get the MediaStore to index that file, such as:

    MediaScannerConnection.scanFile(
      this, 
      new String[] {file.getAbsolutePath()}, 
      null, 
      new OnScanCompletedListener() {
         @Override
         public void onScanCompleted(String path, Uri uri) {
            // do something if you want
         }
      });