我使用Phonegap(2.5)從android(4.0)中獲取聯繫人圖像,以與頭像和名稱建立聯繫人列表。Phonegap android handle null contact image
聯繫人頭像得到細如URL數據(例如數據:內容://com.android.contacts/contacts/189/photo),但我不知道如何處理如果該網址指向一個空圖像(因爲它會在該聯繫人項目中顯示一個帶有問號的藍色方塊沒有安裝avarta)。如果圖像爲空或沒有設置,那麼它應該是我的默認圖片網址。
...
navigator.contacts.find(
['id', 'name', 'phoneNumbers', 'photos', 'displayName'],
function(deviceContacts) {
for (var i = 0; i < deviceContacts.length; i++) {
var deviceContact = deviceContacts[ i ];
if (deviceContact.photos !== null){
img = deviceContact.photos[0].value; //url to image
my_img_item.setSrc(img);
//how to check if image is null or not setup then show default image?
}
...
}
請大家幫忙,謝謝大家。
這不是真的在我看來,你在這裏失去了什麼提示,爲什麼不檢查deviceContact.photos [0] .value爲空或空值, ied案例只是將URL用於my_img_item.setSrc(img)處的默認圖像? – snrlx
不,它始終在我的聯繫人列表(內容://com.android.contacts/contacts/xxx/photo)中有xxx聯繫人ID。所以與null比較是行不通的。 (谷歌帳戶的聯繫人同步) – Hardy
@哈迪你可以請你看看這個問題'http:// stackoverflow.com/questions/18375033 /無法顯示聯繫人數據圖像電話gap' – Hunt