private byte[] getAvatarFor(String remoteAccount) { try { VCardManager manager = VCardManager.getInstanceFor(mConnection); byte[] data; VCard card; if (remoteAccount == null || remoteAccount.isEmpty()) { card = manager.loadVCard(); } else { card = manager.loadVCard(remoteAccount); } if (card == null) return null; data = card.getAvatar(); if (data != null && data.length > 0) { return data; } return null; } catch (Exception exc) { Logger.debug(TAG, "Can't get vCard for " + remoteAccount); return null; } }
private boolean loadVCard (ContentResolver resolver, String jid) { try { debug(TAG, "loading vcard for: " + jid); EntityBareJid bareJid = JidCreate.entityBareFrom(jid); VCardManager vCardManager = VCardManager.getInstanceFor(mConnection); VCard vCard = vCardManager.loadVCard(bareJid); Contact contact = mContactListManager.getContact(bareJid.toString()); if (!TextUtils.isEmpty(vCard.getNickName())) { if (!vCard.getNickName().equals(contact.getName())) { contact.setName(vCard.getNickName()); mContactListManager.doSetContactName(contact.getAddress().getBareAddress(), contact.getName()); } } //check for a forwarding address if (vCard.getJabberId() != null && (!vCard.getJabberId().equals(bareJid.toString()))) { contact.setForwardingAddress(vCard.getJabberId()); } else { contact.setForwardingAddress(null); } // If VCard is loaded, then save the avatar to the personal folder. String avatarHash = vCard.getAvatarHash(); if (avatarHash != null) { byte[] avatarBytes = vCard.getAvatar(); if (avatarBytes != null) { debug(TAG, "found avatar image in vcard for: " + bareJid.toString()); debug(TAG, "start avatar length: " + avatarBytes.length); int rowsUpdated = DatabaseUtils.updateAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, avatarBytes, bareJid.toString()); if (rowsUpdated <= 0) DatabaseUtils.insertAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, mProviderId, mAccountId, avatarBytes, avatarHash, bareJid.toString()); return true; } } } catch (Exception e) { debug(TAG, "err loading vcard: " + e.toString()); if (e.getMessage() != null) { String streamErr = e.getMessage(); if (streamErr != null && (streamErr.contains("404") || streamErr.contains("503"))) { return false; } } } return false; }
/** * Save this vCard for the user connected by 'connection'. XMPPConnection should be authenticated * and not anonymous. * * @param connection the XMPPConnection to use. * @throws XMPPErrorException thrown if there was an issue setting the VCard in the server. * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException * @deprecated use {@link VCardManager#saveVCard(VCard)} instead. */ @Deprecated public void save(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException { VCardManager.getInstanceFor(connection).saveVCard(this); }
/** * Load VCard information for a given user. XMPPConnection should be authenticated and not anonymous. * @throws XMPPErrorException * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException * @deprecated use {@link VCardManager#loadVCard(String)} instead. */ @Deprecated public void load(XMPPConnection connection, String user) throws NoResponseException, XMPPErrorException, NotConnectedException { VCard result = VCardManager.getInstanceFor(connection).loadVCard(user); copyFieldsFrom(result); }