如何在Quickblox中管理聊天(QBChatDialog)中的用户个人资料照片

时间:2018-11-27 09:26:27

标签: android chat quickblox quickblox-android

我必须在我的应用程序中集成Quickblox聊天服务。我已经使用其文档完成了集成部分,但是如何设置用户的个人资料照片并使其显示在QBChatDialog中。我经历过此link,但认为它不会使我工作。请尽快回复。

1 个答案:

答案 0 :(得分:0)

要上传或更新头像,请使用以下代码段:

// just create any file
File avatar = ...; 
// Upload new avatar to Content module
Boolean fileIsPublic = false;

QBContent.uploadFileTask(file1, fileIsPublic, null, new QBEntityCallback<QBFile>() {
@Override
public void onSuccess(QBFile qbFile, Bundle params) {

    int uploadedFileID = qbFile.getId();

    // Connect image to user
    QBUser user = new QBUser();
    user.setId(300);
    user.setFileId(uploadedFileID);

    QBUsers.updateUser(user, new QBEntityCallback<QBUser>(){
        @Override
        public void onSuccess(QBUser user, Bundle args) {

        }

        @Override
        public void onError(QBResponseException errors) {

        }
    });
}

@Override
public void onError(QBResponseException errors) {

}
},new QBProgressCallback() {
@Override
public void onProgressUpdate(int progress) { 
}
});

现在其他用户可以看到您的头像:

int userProfilePictureID = user.getFileId(); // user - an instance of QBUser class

QBContent.downloadFileById(userProfilePictureID, new QBEntityCallback<InputStream>(){
@Override
public void onSuccess(InputStream inputStream, Bundle params) {

}

@Override
public void onError(QBResponseException errors) {

}
}, new QBProgressCallback() {
@Override
public void onProgressUpdate(int progress) {

}
});