Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load Vcards with Smack (Android) in Openfire Server

I am implementing a messaging application with the XMPP protocol and Openfire server on android platform. I need save and load my own Vcard and other users vcard. At the moment, I managed to keep my vCard on the server and can load it again. The problem is with the other users Vcards, server always return XMPPError: feature-not-implemented - cancel.

I use this libraries:

compile 'org.igniterealtime.smack:smack-android:4.1.2-SNAPSHOT'
compile 'org.igniterealtime.smack:smack-tcp:4.1.2-SNAPSHOT'
compile 'org.igniterealtime.smack:smack-extensions:4.1.2-SNAPSHOT'

Show the code:

Save my own Vcard (Work fine).

VCardManager vCardManager = VCardManager.getInstanceFor(connection);
VCard vCard;
vCard = vCardManager.loadVCard();
vCard.setNickName("User name");
URL urldefault = new URL("Avatar URL");
InputStream stream = urldefault.openStream();
byte[] avatar1 = readBytes(stream);
vCard.setAvatar(avatar1, "avatar1/jpg");
vCard.setEmailHome("user email");
vCard.setPhoneHome("mobile", "888888888");
vCardManager.saveVCard(vCard);

Load my own Vcard (Work fine)

VCard vCard = null;
VCardManager vCardManager = VCardManager.getInstanceFor(connection);
vCard = vCardManager.loadVCard();

The problem is here. Load other user Vcard:

VCardManager vCardManager = VCardManager.getInstanceFor(connection);
boolean isSupported = vCardManager.isSupported(user);
if (isSupported)  // return true
    vCard = vCardManager.loadVCard(user);

The user name to load Vcard is correct.

Any ideas?

Thanks in advance.

like image 834
Alejandro Martínez Martínez Avatar asked Jun 05 '15 15:06

Alejandro Martínez Martínez


1 Answers

The issue you might be facing is the suffix for the JID. The connection.getUser() method returns the JID as [email protected]/Smack. To get the vCard details, you need to query it as [email protected] (without the /Smack). Try that out and let me know if it works.

like image 74
y0da Avatar answered Sep 18 '22 23:09

y0da