在重新启动平板电脑Asus Transformer之前,录制的视频在我的其他活动中不可见

时间:2012-11-06 13:00:50

标签: android android-intent video-recording

我创建了一个包含许多活动的项目。一项活动是录制视频,工作正常。我可以在指定的文件夹中看到录制的视频而无需重新启动平板电脑。

但是当我尝试使用查询在其他一些活动中查找该文件夹中的所有视频时,请参阅下面的代码。然后,在重新启动平板电脑之前,我无法看到录制的视频。在开始使用平板电脑之前,我只能看到旧的录制视频。我无法理解这种奇怪的行为。

任何人都可以对这个问题有所了解吗?

感谢。

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());
    }

}

1 个答案:

答案 0 :(得分:1)

如果您将文件存储在外部存储设备上,则需要使用MediaScannerConnectionMediaStore索引该文件,例如:

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