asmack获取用户头像和设置昵称与获取好友昵称

获取昵称

VCard vCard = new VCard();
vCard.load(Asmackconniciton.connection,number+ "@linhuic99.vicp.cc");
Log.d("ccc","昵称是"+vCard.getOrganization()); //公司
Log.d("ccc","昵称是"+vCard.getNickName());

设置昵称

VCard vCard1 = new VCard();
vCard1.setNickName("我是小伍");
vCard1.setOrganization("当前这个人的电话号码当前这个人的电话号码当前这个人的电话号码");
vCard1.save(Asmackconniciton.connection);

获取好友头像

final VCard vcard = new VCard();
try {
    if (tag.equals("my")) {
       vcard.load(Asmackconniciton.connection);} 
    else {
       vcard.load(Asmackconniciton.connection, user+ "@linhuic99.vicp.cc");}
    } 
catch (XMPPException e1) {}
if (vcard == null || vcard.getAvatar() == null) {
        Log.i("xxx", vcard + "是空的");
        return;
    }
try {
        System.out.println("获取用户头像信息: " + user);
        ByteArrayInputStream bais = new ByteArrayInputStream(
                vcard.getAvatar());
        byte buf[] = new byte[1024];
        if (tag.equals("my")) {
            download = new File(Environment.getExternalStorageDirectory()
                    + "/.IMTONG/Vcard/Head/my.png");
        } else {
            download = new File(Environment.getExternalStorageDirectory()
                    + "/.IMTONG/Vcard/Head/" + filename + ".png");
        }
        FileOutputStream fos = new FileOutputStream(download);
        do {
            // 循环读取
            int numread = bais.read(buf);
            if (numread == -1) {
                break;
            }
            fos.write(buf, 0, numread);
        } while (true);
        bais.close();
        fos.close();

你可能感兴趣的:(asmack获取用户头像和设置昵称与获取好友昵称)