Skip to content Skip to sidebar Skip to footer

How To Accept Invitation In Muc?

I am developing chat application with xmpp. I have created group using MUC and sent invitation to other user. but i don't know how to accept and decline invitation. here is my code

Solution 1:

you need to auto join while getting an invitation, here is code while a connection is done.

MultiUserChatManager.getInstanceFor(MyApplication.connection).addInvitationListener(newInvitationListener() {
        @OverridepublicvoidinvitationReceived(XMPPConnection conn, MultiUserChat room, EntityJid inviter, String reason, String password, Message message, MUCUser.Invite invitation) {
            //  Log.e(TAG, "invitationReceived() called with: conn = [" + conn + "], room = [" + room + "], inviter = [" + inviter + "], reason = [" + reason + "], password = [" + password + "], message = [" + message + "], invitation = [" + invitation + "]");LogM.e("invitationReceived() called with: conn = [" + conn + "], room = [" + room + "], inviter = [" + inviter + "], reason = [" + reason + "], password = [" + password + "], message = [" + message + "], invitation = [" + invitation + "]");

            try {
                Resourcepart nickname = null;
                try {
                    nickname = Resourcepart.from("MY_JID_HERE");
                } catch (XmppStringprepException e) {
                    e.printStackTrace();
                }

                try {

                    room.join(nickname); //while get invitation you need to join that room
                    room.getRoom().getLocalpart();
                } catch (SmackException.NoResponseException e) {
                    e.printStackTrace();
                } catch (SmackException.NotConnectedException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (MultiUserChatException.NotAMucServiceException e) {
                    e.printStackTrace();
                }

                Log.e(TAG, "join room successfully");

            } catch (XMPPException e) {
                e.printStackTrace();
                Log.e(TAG, "join room failed!");
            }

        }
    });

Solution 2:

I found the answer for decline invitation.

This function is moved to the MultiUserChatManager, it has no relation to a specific instance of a MultiUserChat, so it was a static and is now a function of the manager.

MultiUserChatManager.getInstanceFor(connection).decline(roomJID,inviter.asEntityBareJid(),"reason");

But what to do for accept invitation? Anyone can answer me, please ?

Post a Comment for "How To Accept Invitation In Muc?"