我正在尝试使用以下代码获取联系人资料图片,即联系人数据的头像,PhoneGap
但android
我得到了以下网址作为回报,我不知道应该如何在img
标签中显示它。
代码
var defaultImagePath ='../resources/images/default_usr.png'
var img = contacts[i].photos != null ?
contacts[i].photos[0].value : defaultImagePath;
返回的网址是
内容://com.android.contacts/contacts/739/photo
现在,当最终在列表中时,我尝试使用
<img src="content://com.android.contacts/contacts/739/photo"/>
但它没有显示任何东西?那么我将如何显示联系人图像?
我有最新PhoneGap
版本
我用过
window.resolveLocalFileSystemURI(contacts[i].photos[0].value, this.onResolveSuccess, this.fail);
但我收到以下运行时错误
JNI ERROR (app bug): attempt to use stale local reference in phonegap
即使我在android中指定了以下权限
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
更新
loadContacts:function(){
var arr = [];
var filter = ["displayName", "name", "phoneNumbers","emails","addresses","photos"];
var options = new ContactFindOptions();
options.filter="";
options.multiple=true;
navigator.contacts.find(filter,
function(contacts) {
for (var i = 0; i < contacts.length; i++) {
if (contacts[i].photos) {
for (var j = 0; j < contacts[i].photos.length; j++) {
returnValidPhoto(contacts[i].photos[j], function(answer) {
console.log(answer);
if(contacts[i].photos[j]!=null);
contacts[i].photos[j].value=answer;
});
var contactData = new ContactData("Name" ,
"09090909",
contacts[i].photos[j].value);
arr.push(contactData);
}
}
}
Ext.getStore('ContactStore').setData(arr);
// document.getElementById("contactdata").innerHTML = data;
}, function(err) {
alert(err);
},options);
}
这是图像功能
function returnValidPhoto(url,callback){
console.log("IMAGE CALLED");
var img = new Image();
img.onload = function() {
//Image is ok
console.log("IMAGE OK");
callback(url.value);
};
img.onerror = function(err) {
//Returning a default image for users without photo
console.log("IMAGE FAILED");
url.value = "/resources/images/default_usr.png";
callback("/resources/images/default_usr.png");
}
img.src = url.value;
};