简体   繁体   English

Android使用xmpp接受群聊邀请

[英]Android accept invitation of group chat by using xmpp

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. 我正在使用以下方法在xmpp中获取群聊邀请,也成功获取了邀请,但是在接受邀请的某个地方无法接受邀请。

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

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

I hope it help you... 希望对您有帮助...

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

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