繁体   English   中英

下载后画廊不显示图像吗?

[英]Gallery does not show the image after download?

我有以下代码将图像从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?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM