org.jivesoftware.smackx.vcardtemp.VCardManager Java Examples

The following examples show how to use org.jivesoftware.smackx.vcardtemp.VCardManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmppConnection.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example #2
Source File: VCard.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * 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 if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @deprecated use {@link VCardManager#saveVCard(VCard)} instead.
 */
@Deprecated
public void save(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    VCardManager.getInstanceFor(connection).saveVCard(this);
}
 
Example #3
Source File: VCard.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Load VCard information for a given user. XMPPConnection should be authenticated and not anonymous.
 *
 * @param connection connection.
 * @param user user whos information we want to load.
 *
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @deprecated use {@link VCardManager#loadVCard(EntityBareJid)} instead.
 */
@Deprecated
public void load(XMPPConnection connection, EntityBareJid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    VCard result = VCardManager.getInstanceFor(connection).loadVCard(user);
    copyFieldsFrom(result);
}