【发布时间】:2019-12-12 18:19:15
【问题描述】:
我尝试在下载后在图库中提供图片, 我使用MediaScannerPlugin ,所以问题是如何访问cordova 的插件? 这是我的代码:
const fileTransfer: FileTransferObject = this.transfer.create();
let encoded_url = encodeURI(img_url);
fileTransfer.download(encoded_url, this.file.externalApplicationStorageDirectory+"download/"+img_id+".png", true).then((entry) => {
// Download completed successfully
let toast = this.toastCtrl.create({
message: 'Image downloaded.',
cssClass:'toastStyle',
duration: 2000,
position: 'bottom'
});
toast.present();
// var cordova:any; with this line I got no errors but the downloaded image aren't available in the gallery
cordova.plugins.MediaScannerPlugin.scanFile( this.file.externalApplicationStorageDirectory+"download/"+img_id+".png");
}, (error) => {
// error was happened
console.log("download error source "+ error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
});
我得到的错误:
未捕获(承诺中):类型错误:无法读取未定义的属性“插件”类型错误:无法读取未定义的属性“插件”
离子版本 4.6.0
Cordova 版本 9.0.0
谢谢。
【问题讨论】:
标签: android node.js typescript cordova ionic-framework