问题
After hours of debugging and trying to find out why the file transfer was not working using aSmack, while normal messaging was, I finally managed to pin it down to this.
The Openfire server is sending the Rosters' JID missing the / at the end when I follow the method given in the Smack documentation to get a user's Roster list.
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry r : entries) {
Log.v("Gabriel","Receiving: " + r.getUser());
}
For example if I receive a message from the user gabriel, I get the "From" as:
gabriel@dragonov/Smack
But the r.getUser() returns to the user as
gabriel@dragonov
Even
connection.getRoster().getPresence(contactName).getFrom()
is returning is as "gabriel@dragonov".
This is causing the File transfer to fail, but oddly not the regular messaging. However when I manually add the /Smack at the end of
OutgoingFileTransfer transferr = manager.createOutgoingFileTransfer(contactJID+"/Smack");
it works.
My question is, how can I receive the full JID with the resource part included or configure the file transfer so that it doesn't fail when using a bare JID?
Edit:
I have tried the following method:
Log.v("Gabriel", entries.size() + " buddy(ies):");
for (RosterEntry r : entries) {
Log.v("Pat","adding: " + r.getType() + " " + r.getName());
contacts.add(r.getUser());
}
for (String contact : contacts){
Iterator<org.jivesoftware.smack.packet.Presence> presences = connection.getRoster().getPresences(contact);
Log.v("Gabriel", contact+" has: ");
while(presences.hasNext()){
Log.v("Gabriel",presences.next().getFrom());
}
}
But I am still getting the bare ID.
The output: gabriel@dragonov has: gabriel@dragonov
回答1:
Use Iterator<Presence> Roster.getPresences(String user) to get the presence information from all known resources of a user. For this Presence instances getFrom()
should return a full JID which you can use in FileTransferManager.createOutgoingFileTransfer()
.
I have created SMACK-430, regarding the use of a full JID in createOutgoingFileTranfer()
. It really should throw an exception so that smack users don't have to debug hours to find the reason (although it's stated in the method javadoc). SMACK-430 also explains why FileTransferManager needs a full JID and can not be used with a bare JID.
来源:https://stackoverflow.com/questions/15518440/smacks-filetransfermanager-createoutgoingfiletransfer-only-accepts-full-jids-h