Android的使用XMPP接受群聊的邀请 [英] Android accept invitation of group chat by using xmpp

查看:902
本文介绍了Android的使用XMPP接受群聊的邀请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面得到XMPP邀请群聊,也成功地获得邀请,但在接受邀请无法接受邀请的地方。

这是我的code的邀请,并接受群聊的:

 公共静态无效addMUC(){
                MultiUserChat.addInvitationListener(连接,新InvitationListener(){
                    @覆盖
                    公共无效invitationReceived(康涅狄格州的连接,最后弦乐房,字符串邀请人,
                            reason字符串,字符串密码,邮件消息){                        Constant.showGroupChatInvitationAlert(Constant.MESSAGE_GROUP_CHAT,究其原因,
                                房间里,康涅狄格州,邀请人,_s prefs.getString(USERNAME,),_s prefs.getString(密码,));
                    }
                });
            }
    公共静态无效showGroupChatInvitationAlert(最后字符串的称号,最后字符串的消息,
                最后弦乐ROOMNAME,最终连接康涅狄格州,最后弦乐邀请人,最后弦乐用户,最终的字符串密码){            新主题(新的Runnable接口(){
        公共无效的run(){joinMultiUserChat(Constant.userName,Constant.password,roomname.split(@)[0]);
        }
    })。开始();        }公共静态MultiUserChat joinMultiUserChat(用户字符串,字符串密码字符串roomsName){
        尝试{            XMPPSmackConnection.getInstance();
            。StrictMode.ThreadPolicy政策=新StrictMode.ThreadPolicy.Builder()permitAll()建();
            StrictMode.setThreadPolicy(政策);
            //使用XMPPConnection一个MultiUserChat窗口
            MultiUserChat睦=新MultiUserChat(XMPPSmackConnection.connection,roomsName
                    +@conference。 + XMPPSmackConnection.connection.getServiceName());            //聊天室服务的数量将决定接受历史记录
            DiscussionHistory历史=新DiscussionHistory();
            history.setMaxStanzas(0);
            //history.setSince(new日期());
            //用户加入聊天室
            muc.join(用户名,密码,历史,SmackConfiguration.getPacketReplyTimeout());
            的System.out.println(会议室成功......);
            返回睦;
        }赶上(XMPPException E){
            e.printStackTrace();
            的System.out.println(会议室失败......);
            返回null;
        }
    }


解决方案

连接到服务器之前添加此扩展管理器可的ProviderManager

  ProviderManager.getInstance()addExtensionProvider(X,http://jabber.org/protocol/muc#user,新MUCUserProvider());

我希望它能帮助你...

I am using below to get invitation in xmpp for group chat and also successfully getting invitation but somewhere in acceptance of invitation not able to accept the invitation.

This is my code for invitation and acceptance of group chat:

     public static void addMUC() {
                MultiUserChat.addInvitationListener(connection, new InvitationListener() {
                    @Override
                    public void invitationReceived(Connection conn, final String room, String invitor,
                            String reason, String password, Message message) {

                        Constant.showGroupChatInvitationAlert(Constant.MESSAGE_GROUP_CHAT, reason, 
                                room,conn,invitor, _sPrefs.getString("USERNAME", ""), _sPrefs.getString("PASSWORD", ""));


                    }
                });
            }


    public static void showGroupChatInvitationAlert(final String title, final String message,
                final String roomname,final Connection conn,final String inviter, final String user,final String password) {

            new Thread(new Runnable() {
        public void run() {

joinMultiUserChat(Constant.userName, Constant.password, roomname.split("@")[0]);
        }
    }).start();

        }

public static MultiUserChat joinMultiUserChat(String user, String password, String roomsName) {  
        try {  

            XMPPSmackConnection.getInstance();
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy); 
            // Create a MultiUserChat window using XMPPConnection  
            MultiUserChat muc = new MultiUserChat(XMPPSmackConnection.connection, roomsName  
                    + "@conference." + XMPPSmackConnection.connection.getServiceName());  



            // The number of chat room services will decide to accept the historical record  
            DiscussionHistory history = new DiscussionHistory();  
            history.setMaxStanzas(0);  
            //history.setSince(new Date());  
            // Users to join in the chat room  
            muc.join(user, password, history, SmackConfiguration.getPacketReplyTimeout());  
            System.out.println("The conference room success....");  
            return muc;  
        } catch (XMPPException e) {  
            e.printStackTrace();  
            System.out.println("The conference room to fail....");  
            return null;  
        }  
    }

解决方案

add this extension manager to ProviderManager before connecting to server

ProviderManager.getInstance().addExtensionProvider("x", "http://jabber.org/protocol/muc#user",  new MUCUserProvider());

I hope it help you...

这篇关于Android的使用XMPP接受群聊的邀请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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