繁体   English   中英

Smack API抛出item-not-found(404)异常

[英]Smack API throws item-not-found(404) exception

这是代码

Iterator i = MultiUserChat.getJoinedRooms(connectionManager.getXMPPConnection(), "test123@dulanjaya-pc");
while(i.hasNext()) {
    System.out.println(i.next());
}

想通了。 需要将服务作为/ Smack

Iterator i = MultiUserChat.getJoinedRooms(connectionManager.getXMPPConnection(), "test123@dulanjaya-pc/Smack");

也许这段代码片段对您有所帮助。

boolean supports = MultiUserChat.isServiceEnabled(connection,"test3@pc2010102716/spark");    
if(supports) {   
                Iterator<String> joinedRooms = MultiUserChat.getJoinedRooms(connection,"test3@pc2010102716/spark");  
                while(joinedRooms.hasNext()) {   
                    System.out.println("test3 has joined Room " + joinedRooms.next());   
                }   
            }

getJoinedRooms的源代码如下所示,该方法的第二个参数需要一个完全限定的xmpp ID。 它显示的ID示例不完整,完整的ID应包含资源名称,例如/ smack,/ spark和/ android。

 /**
     * Returns an Iterator on the rooms where the requested user has joined. The Iterator will
     * contain Strings where each String represents a room (e.g. room@muc.jabber.org).
     *
     * @param connection the connection to use to perform the service discovery.
     * @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
     * @return an Iterator on the rooms where the requested user has joined.
     */
    public static Iterator<String> getJoinedRooms(Connection connection, String user) {
        try {
            ArrayList<String> answer = new ArrayList<String>();
            // Send the disco packet to the user
            DiscoverItems result =
                ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(user, discoNode);
            // Collect the entityID for each returned item
            for (Iterator<DiscoverItems.Item> items=result.getItems(); items.hasNext();) {
                answer.add(items.next().getEntityID());
            }
            return answer.iterator();
        }
        catch (XMPPException e) {
            e.printStackTrace();
            // Return an iterator on an empty collection
            return new ArrayList<String>().iterator();
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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