【问题标题】:Gallery does not show the image after download?下载后图库不显示图像?
【发布时间】:2014-12-02 17:47:21
【问题描述】:

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

【问题讨论】:

  • 确实如此。对文件使用媒体扫描仪。但是如果你找到了,那么再次谷歌/搜索,因为该代码之前已经发布在这个网站上。
  • 我找到了答案。我发布了。

标签: javascript android cordova cordova-plugins ionic


【解决方案1】:

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

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

【讨论】:

  • 我在控制台日志中未定义。有什么想法吗?
猜你喜欢
  • 1970-01-01
  • 2020-05-13
  • 1970-01-01
  • 2018-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-08
  • 1970-01-01
相关资源
最近更新 更多