Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Gallery不会立即刷新新录制的视频_Android_Video_Gallery - Fatal编程技术网

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

Android Gallery不会立即刷新新录制的视频,android,video,gallery,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

使用以下代码,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中我看到一个错误,即我的活动泄漏了MediaScanner连接:

    private void addVideoGallery() {

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

}
解决方法:

      ContentValues values = new ContentValues();

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