Android Gallery不会立即用新录制的视频刷新 [英] Android Gallery not instantly refreshed with new recorded videos

查看:137
本文介绍了Android Gallery不会立即用新录制的视频刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

With the following code, the Android Gallery is not refreshed instantly. If i try to see the new files, I need to restart the device or wait.

    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 Connection:

With this other code, all works fine but in the logcat I see an error that my Activity has leaked MediaScanner Connection:

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

这篇关于Android Gallery不会立即用新录制的视频刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆