How can I upload user's profile picture to server when registering new user ?

I am developing an android app using XMPP (Openfire) . User can register new account from that app and they can set their profile picture in register form. I want to know how can I save that profile picture to Openfire server.

Answers


You can use the vCard method that is given for Smack 4.1. Load the user's vCard when they are editing their profile information. Then, allow them to upload their avatar. Once they save it, you convert the Bitmap to a byte array, which is then sent to save vCard. Here's an example:

// Let the user pick their avatar
Bitmap bitmap;
// Take the avatar and convert it into a byte array:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// 90 refers the the compression quality. For PNG, the quality is ignored
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream);
byte[] avatarByte = stream.toByteArray();

// Once you get the byte array from the image, set the byte array to the vCard avatar
vCard.setAvatar(avatarByte);

// Then you can save the vCard details
vCardManager.saveVCard(vCard);

Hope that helps


Need Your Help

ComboBox SelectedValue property doesn't work

c# .net winforms data-binding combobox

I'm trying to add objects into a combobox and use SelectedValue property to select and item in the combobox but it does not work: SelectedValue is still null after the assignment.

How to remove text/characters from an Excel cell

excel excel-formula

I am looking for a way to remove any text from a cell and leave just numbers. So far I have found a few examples, but they either target predefined text or specialized characters.