如何使用phonegap for android
将图像从网址保存到相册我的代码是:
<a href="#" onclick="saveToPhotoAlbum('https://build.phonegap.com/images/icon.png', true);">Click to save!</a>
答案 0 :(得分:0)
您需要使用文件传输插件
function saveToPhotoAlbum(myuri)
{
var fileTransfer = new FileTransfer();
var uri = encodeURI(myuri);
var filePath="cdvfile://localhost/persistent/myImageFolder/myImage.jpg";
fileTransfer.download(
uri,
filePath,
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
false,
{
headers: {
"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
}
);
}
<a href="#" onclick="saveToPhotoAlbum('https://build.phonegap.com/images/icon.png');">Click to save!</a>