Smack的FileTransferManager.createOutgoingFileTransfer仅接受完整的JID.如何确定Smack中用户的完整JID? [英] Smack's FileTransferManager.createOutgoingFileTransfer only accepts full JIDs. How can I determine the full JID of a user in Smack?

查看:130
本文介绍了Smack的FileTransferManager.createOutgoingFileTransfer仅接受完整的JID.如何确定Smack中用户的完整JID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过数小时的调试,并试图找出为什么使用aSmack无法进行文件传输的原因,而正常的消息传递却得以解决,

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.

当我按照Smack文档中给出的方法获取用户的名册列表时,Openfire服务器会发送缺少/的名册JID.

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());
}      

例如,如果我收到来自用户gabriel的消息,我将得到发件人"为:

For example if I receive a message from the user gabriel, I get the "From" as:

gabriel@dragonov/Smack

但是r.getUser()返回给用户

But the r.getUser() returns to the user as

gabriel@dragonov

甚至

connection.getRoster().getPresence(contactName).getFrom()

返回的是"gabriel @ dragonov".

is returning is as "gabriel@dragonov".

这导致文件传输失败,但是奇怪的是常规消息传递失败.但是,当我在末尾手动添加/Smack时

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");

有效.

我的问题是,如何接收包含资源部分的完整JID或配置文件传输,以使使用裸JID时文件传输不会失败?

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?

我尝试了以下方法:

 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());
        }           
    }

但是我仍然得到裸露的ID.

But I am still getting the bare ID.

输出: gabriel @ dragonov具有: gabriel @ dragonov

The output: gabriel@dragonov has: gabriel@dragonov

推荐答案

使用

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().

我创建了 SMACK-430 ,涉及到在createOutgoingFileTranfer().它确实应该抛出一个异常,以便smack用户不必调试几个小时就可以找到原因(尽管在javadoc方法中有说明). SMACK-430还解释了为什么FileTransferManager需要完整的JID,而不能与裸JID一起使用.

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.

这篇关于Smack的FileTransferManager.createOutgoingFileTransfer仅接受完整的JID.如何确定Smack中用户的完整JID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆