1

我有以下代码将图像从 url 保存到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 卡中的文件。但它在图库应用程序中不可见。当我搜索它时,我发现我们应该对该文件运行一些媒体扫描仪。

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

4

1 回答 1

0

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

 // Run media scanner to make it visible in Gallery app.
 cordova.exec(null, null, 'ScanMedia', 'mediaScanner', [result.nativeURL]);
于 2014-12-02T18:29:15.430 回答