简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM