asmack - can't read VCard

2019-08-02 08:23发布

问题:

I did exactly what the answer suggested ( Asmack not loading VCard ) but it still doesn't work. The DEBUG output shows that Smack receives the packet with the VCard information but then throws a ClassCastException in https://github.com/rtreffer/smack/blob/master/source/org/jivesoftware/smackx/packet/VCard.java#L548 and all I get is 'No VCard for xxx@xxx'.

My code:

public VCard getUserVCard() throws XMPPException {
    VCard userVCard = new VCard();
    userVCard.load(connection);
    return userVCard;
}

And some previous initialization:

ConnectionConfiguration config = new ConnectionConfiguration(OF_HOST, OF_PORT, OF_SERVICE_NAME);
config.setDebuggerEnabled(true);
    config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
ProviderManager.getInstance().addIQProvider("vCard ", "vcard-temp", new org.jivesoftware.smackx.provider.VCardProvider());
connection = new XMPPConnection(config);
this.context = context;
try {
    connection.connect();
} catch (XMPPException e) {
    // TODO Auto-generated catch block
        e.printStackTrace();
}

The VCard information in the database is OK - only the final casting fails. Any suggestions?

回答1:

I finally decided not only to add the VCardProvider but the whole nine yards in the configuration following this post getSearchForm returns null when using UserSearch in XMPP with aSmack and it worked.