我看到了几篇与此相关的帖子,例如 Ref但不为我工作。我试过如下
第一种方法:
直接从联系人图像值设置图像源
var myImg = document.getElementById("cimg");
myImg.src = contacts[i].photos[0].value;
这个不显示img标签中的图片。
第二种方法:
将联系人图像值传递给文件下载选项
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fs){
fs.root.getFile("temp.jpg", {create: true, exclusive: false},
function(entry){
//alert(entry.toURL());
var fileTransfer = new FileTransfer();
fileTransfer.download(
contacts[i].photos[0].value, // the filesystem uri you mentioned
entry.fullPath,
function(entry) {
// do what you want with the entry here
console.log("download complete: " + entry.fullPath);
var src = entry.fullPath;
//$("").append('<img src="'+src+'" >');
},
function(error) {
alert("error source " + error.source);
console.log("error target " + error.target);
console.log("error code " + error.code);
console.log(error);
},
false,
null
);
}, function(e){
console.log("file create error",e);
});
}, null);
这个显示错误如 07-28 07:37:56.468: E/FileTransfer(20986): {"target":"file:\/\/\/mnt\/sdcard\/Android\/data\/io.cordova.hellocordova\/cache\/temp.jpg","http_status":0,"code":3,"source":"content:\/\/com.android.contacts\/contacts\/2\/photo","exception":"读取失败:EINVAL(无效参数)"}
07-28 07:37:56.468:E/FileTransfer(20986):java.io.IOException:读取失败:EINVAL(无效参数)
编辑:
我的 phonegap contact[i].photo[0].value 返回类似 "content://com.android.contacts/contacts/1/photo"
如何解决这个问题。请帮助我。
最佳答案
请检查您正在测试的安卓版本。因为 android 2.0 -> 2.2 结构有很多变化.. 你可以在 android 4.0 + 以上尝试吗?
关于javascript - 不显示来自 Phonegap 的联系人图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24991983/