Android Gallery not instantly refreshed with new recorded videos

百般思念 提交于 2019-12-24 10:45:49

问题


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


}

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

}

回答1:


Solved with:

      ContentValues values = new ContentValues();

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


来源:https://stackoverflow.com/questions/24555575/android-gallery-not-instantly-refreshed-with-new-recorded-videos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!