Android画廊不会立即刷新新录制的视频

时间:2014-07-03 13:52:00

标签: android video gallery

使用以下代码,Android Gallery不会立即刷新。如果我尝试查看新文件,我需要重启设备或等待。

    private void addVideoGallery() {

    File f = new File(outputfilename);
    Intent mediaScannerIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    Uri fileContentUri = Uri.fromFile(f); 
    mediaScannerIntent.setData(fileContentUri);
    this.sendBroadcast(mediaScannerIntent);         


}

使用其他代码,一切正常但在logcat中我看到一个错误,我的Activity已泄露MediaScanner连接:

    private void addVideoGallery() {

    File f = new File(outputfilename);
    MediaScannerConnection.scanFile(this, new String[] { f.getPath() }, new String[] {   "video/mp4" }, null);

}

1 个答案:

答案 0 :(得分:0)

解决:

      ContentValues values = new ContentValues();

      values.put(MediaStore.Video.Media.DATA, outputfilename);
      ContentResolver resolver = MainActivity.this.getContentResolver();
      resolver.insert(Video.Media.EXTERNAL_CONTENT_URI, values);