Java Code Examples for org.jivesoftware.smackx.packet.VCard#save()

The following examples show how to use org.jivesoftware.smackx.packet.VCard#save() . 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: XSCHelper.java    From PracticeCode with Apache License 2.0 6 votes vote down vote up
/**
 * 设置用户头像
 *
 * @param bytes 图像。从图像/图像文件获取到的字节集
 * @return tag  标签。如设置成功标签返回修改时间,设置失败返回null
 */
public String setAvatar(byte[] bytes) {
    String tag;

    //确认网络状态
    if(getConnection() == null){
        return null;
    }
    //确认获取名片
    VCard card = getVCard();
    if(card == null){
        return null;
    }
    //开始获取信息
    try {
        //创建图像的唯一标识
        tag = System.currentTimeMillis() + UserInfoBasic.account;
        card.setAvatar(bytes);
        card.setField(AVATAG, tag);
        card.save(getConnection());
    } catch (XMPPException e) {
        tag = null;
    }

    return tag;
}
 
Example 2
Source File: XSCHelper.java    From PracticeCode with Apache License 2.0 6 votes vote down vote up
/**
 * 设置基础信息
 *
 * @param password 可null。非空则更改登录密码为password
 * @param nickName 可null。非空则更改昵称为nickName
 */
public void setUserBasicData(String password, String nickName) {
    try {
        if(getConnection() == null || !getConnection().isAuthenticated())
            return;

        if (password != null) {
            getConnection().getAccountManager().changePassword(password);
        }

        VCard card = getVCard();
        if(nickName != null && card != null){
            card.setNickName(nickName);
            card.save(getConnection());
        }
    } catch (XMPPException e) {
        e.printStackTrace();
    }
}
 
Example 3
Source File: XSCHelper.java    From PracticeCode with Apache License 2.0 6 votes vote down vote up
/**
 * 设置进阶信息
 *
 * @param map 以String为键、String为值存储的键值对
 */
public void setUserEnhancedData(LinkedHashMap<String, String> map) {
    //如果没有网络连接直接返回
    if(getConnection() == null)
        return;

    try {
        VCard card = getVCard();
        if (card != null) {
            for(Map.Entry<String, String> en : map.entrySet())
                card.setField(en.getKey(), en.getValue());
            card.save(getConnection());
        }
    } catch (XMPPException e) {
        e.printStackTrace();
    }
}
 
Example 4
Source File: XmppConnection.java    From weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 修改用户头像
 * 
 * @param file
 */
public boolean changeImage(File file) {
	if (getConnection() == null)
		return false;
	try {
		VCard vcard = new VCard();
		vcard.load(getConnection());

		byte[] bytes;

		bytes = getFileBytes(file);
		String encodedImage = StringUtils.encodeBase64(bytes);
		vcard.setAvatar(bytes, encodedImage);
		vcard.setEncodedImage(encodedImage);
		vcard.setField("PHOTO", "<TYPE>image/jpg</TYPE><BINVAL>" + encodedImage + "</BINVAL>", true);

		ByteArrayInputStream bais = new ByteArrayInputStream(vcard.getAvatar());
		FormatTools.getInstance().InputStream2Bitmap(bais);

		vcard.save(getConnection());
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
Example 5
Source File: XSCHelper.java    From PracticeCode with Apache License 2.0 5 votes vote down vote up
/**
 * 保存名片信息
 */
public void saveVCard() {
    try {
        VCard card = getVCard();
        if (card != null)
            card.save(getConnection());
    } catch (XMPPException e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: XmppManager.java    From weixin with Apache License 2.0 5 votes vote down vote up
/**
 * 修改用户头像
 * 
 * @param f
 * @throws XMPPException
 * @throws IOException
 */
public void changeUserImage(File f) throws XMPPException, IOException {
	VCard vCard = new VCard();
	vCard.load(getConnection());
	byte[] bytes = getFileBytes(f);

	String encodeImage = StringUtils.encodeBase64(bytes);
	vCard.setAvatar(bytes, encodeImage);
	vCard.setEncodedImage(encodeImage);
	vCard.setField("PHOTO", "<TYPE>image/jpg</TYPE><BINVAL>" + encodeImage + "</BINVAL>", true);

	ByteArrayInputStream bais = new ByteArrayInputStream(vCard.getAvatar());
	FormatTools.getInstance().InputStream2Bitmap(bais);
	vCard.save(getConnection());
}
 
Example 7
Source File: XmppVcard.java    From yiim_v2 with GNU General Public License v2.0 4 votes vote down vote up
public void save(Connection connection) {
	try {
		VCard vCard = new VCard();
		vCard.load(connection, mUserId);

		if (!YiUtils.isStringInvalid(mNickName)) {
			vCard.setNickName(mNickName);
		}

		if (!YiUtils.isStringInvalid(mGender)) {
			vCard.setField(Const.SEX, mGender);
		} else {
			vCard.setField(Const.SEX, Const.FEMALE);
		}

		if (!YiUtils.isStringInvalid(mSign)) {
			vCard.setField(Const.SIGN, mSign);
		}

		if (!YiUtils.isStringInvalid(mCountry)) {
			vCard.setField(Const.COUNTRY, mCountry);
		}

		if (!YiUtils.isStringInvalid(mProvince)) {
			vCard.setField(Const.PROVINCE, mProvince);
		}

		if (!YiUtils.isStringInvalid(mAddress)) {
			vCard.setField(Const.ADDRESS, mAddress);
		}

		vCard.setField(Const.BIRTHDAY, String.valueOf(mBirthday));
		vCard.setField(Const.SECOND_BIRTHDAY,
				String.valueOf(mSecondBirthday));
		vCard.setField(Const.ONLINETIME, String.valueOf(mOnlineTime));

		if (!YiUtils.isStringInvalid(mRealName)) {
			vCard.setField(Const.REALNAME, mRealName);
		}

		if (!YiUtils.isStringInvalid(mBloodGroup)) {
			vCard.setField(Const.BLOOD_GROUP, mBloodGroup);
		}

		if (!YiUtils.isStringInvalid(mPhone)) {
			vCard.setField(Const.PHONE, mPhone);
		}

		if (!YiUtils.isStringInvalid(mOccupation)) {
			vCard.setField(Const.OCCUPATION, mOccupation);
		}

		if (!YiUtils.isStringInvalid(mEmail)) {
			vCard.setField(Const.EMAIL, mEmail);
		}

		if (mAvatar != null && mAvatar.length > 0) {
			vCard.setAvatar(mAvatar);
			YiStoreCache.cacheRawData(mUserId, mAvatar);
		}

		vCard.save(connection);
	} catch (Exception e) {
		// TODO: handle exception
		e.printStackTrace();
	}

	saveToDatabase();
}