Javascript Gallery在下载后不显示图像?
我有以下代码将图像从url保存到Javascript Gallery在下载后不显示图像?,javascript,android,cordova,cordova-plugins,ionic,Javascript,Android,Cordova,Cordova Plugins,Ionic,我有以下代码将图像从url保存到下载文件夹 var filename = url.replace(/^.*[\\\/]/, ''); var filePath = cordova.file.externalRootDirectory + 'Download/' + filename; $cordovaFile.downloadFile(url, filePath, true, {}) .then(function(result) {
下载
文件夹
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吗?我终于找到了答案。在文件下载成功回调中运行媒体扫描程序
// Run media scanner to make it visible in Gallery app.
cordova.exec(null, null, 'ScanMedia', 'mediaScanner', [result.nativeURL]);
的确在文件上使用mediascanner。但如果你找到了thst,那么谷歌/搜索再次出现,因为该代码以前已经发布在这个网站上。我找到了答案。我发布了。我在控制台日志中没有定义。有什么想法吗?