Gallery does not show the image after download?

不羁的心 提交于 2019-12-23 02:49:21

问题


I have following code to save image from url to Download folder

    var filename = url.replace(/^.*[\\\/]/, ''); 
    var filePath = cordova.file.externalRootDirectory + 'Download/' + filename;
    $cordovaFile.downloadFile(url, filePath, true, {})
        .then(function(result) {
          // Success!
          $cordovaToast.showShortCenter('This picture has been saved!');
        }, function(err) {
          $ionicPopup.alert({ title: 'Error!', template: angular.toJson(err) });
        });

It saves the image successfully. I can explore the file in the SD card. But it is not visible in Gallery app. When i search for it, i found that we should run some media scanner on that file.

How do i run media scanner? is there any api?


回答1:


Finally i found an answer. Run the media Scanner inside file download success callback.

 // Run media scanner to make it visible in Gallery app.
 cordova.exec(null, null, 'ScanMedia', 'mediaScanner', [result.nativeURL]);


来源:https://stackoverflow.com/questions/27255757/gallery-does-not-show-the-image-after-download

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