Gallery does not show the image after download?

2019-06-02 01:04发布

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条回答
戒情不戒烟
2楼-- · 2019-06-02 01:32

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]);
查看更多
登录 后发表回答