我有以下代码将图像从 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]);
关于javascript - 下载后图库不显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27255757/