下载后图库不显示图像?

时间:2014-12-02 17:47:22

标签: javascript android cordova cordova-plugins ionic

我有以下代码将图片从网址保存到Download文件夹

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

成功保存图像。我可以在SD卡中浏览该文件。但它在Gallery应用程序中不可见。当我搜索它时,我发现我们应该在该文件上运行一些媒体扫描程序。

如何运行媒体扫描仪?有没有api?

1 个答案:

答案 0 :(得分:0)

最后我找到了答案。在文件下载成功回调中运行媒体扫描程序。

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