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

标签 android android-intent video-recording

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

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

谁能阐明这个问题??

谢谢。

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

}

最佳答案

如果您将文件存储在外部存储上,则需要使用 MediaScannerConnection 获取 MediaStore 来索引该文件,例如:

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

关于android - 在我重新启动平板电脑 Asus Transformer 之前,录制的视频在我的其他 Activity 中不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13251634/

相关文章:

android - 如何更改 Lollipop 中的 DatePicker 日历 View 背景颜色?

java - 验证类错误

android - getIntent().getExtras() 有时会在 Activity 中崩溃

java - 此代码段是否会导致无限循环或其他?

android - 如何在我们自己的 Android 应用程序上使用 KML 绘制叠加层?

Android Wear 应用因桥接通知而被拒绝

android - 由 : java. lang.IllegalStateException 引起:

Android - 录制视频时将麦克风静音

android-camera - 如何让前置摄像头拍摄的视频不反安卓?

android - 如何在MediaRecorder中添加焦点功能?