2

In my chatting application I want to implement Group Chatting functionality. For the same I want to create rooms and send the invitations to my friends to join the room. Here is my code to join and invite the friend to room.

To Create the Room

//Create Room
    btn_CreateRoom = (Button)findViewById(R.id.btn_usermenu_CreateRoom);
    btn_CreateRoom.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            try {
                muc = new MultiUserChat(connection, "room1@conference.abc.com");

                muc.join("Sunil","123456");
                muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));

            } catch (XMPPException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            System.out.println("Room Created");
        }
    });


    btn_Invite = (Button)findViewById(R.id.btn_usermenu_InviteToRoom);
    btn_Invite.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub


            muc.invite("sunil@abc.com", "Please join this room");



        }
    });

}

To recieve the invitation I have implemented an Invitation Listener in my Service Class. But I am unable to receive the invitaion via notification. Wats the problem with the code.

Here is my Invitation Listener.

MultiUserChat.addInvitationListener(connection, new InvitationListener() {

            @Override
            public void invitationReceived(Connection arg0, String arg1, String arg2,
                    String arg3, String arg4, Message arg5) {
                // TODO Auto-generated method stub

                System.out.println("Received??");
                notification("Invitation Received");

Please let me know Why I am not receiving the invitation.??

Thanks

Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
  • you can do logging to know about the status; where your code blocks and whether the listener receives the Callback from server (i.e., from room to join) and client thread is ready to receive the invitation. – static void main Oct 24 '12 at 11:44
  • 1
    Static void main is Right. U should perform debugging and pinpoint the issue so we can help – Sheraz Ahmad Khilji Oct 25 '12 at 06:24
  • @SherazKhilji Yes the invite is sent and I have written my invitation listener in the service class. Invitation is simply sent. but it's not received at all. I have debugged it. – Gaurav Arora Oct 25 '12 at 09:27

3 Answers3

2

you write this code after xmppconnection.connect()

MultiUserChatManager.getInstanceFor(connection).addInvitationListener(new InvitationListener() {
                    @Override
                    public void invitationReceived(XMPPConnection conn, MultiUserChat room, String inviter, String reason, String password, Message message) {
                        MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(conn);
                        try {
                            room.join("pandian");
                        } catch (SmackException.NoResponseException e) {
                            e.printStackTrace();
                        } catch (XMPPException.XMPPErrorException e) {
                            e.printStackTrace();
                        } catch (SmackException.NotConnectedException e) {
                            e.printStackTrace();
                        }
                    }


                });

its work for me ..try it

0

You can try this

public class myclass extends Activity implements InvitationListener{
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
                MultiUserChat.addInvitationListener(Connection,myclass.this);
}
@Override
    public void invitationReceived(Connection conn, final String room,
            String inviter, String reason, String password, Message message) {

        Log.e("inviter", inviter);
        Log.e("message", message.getBody());
        Log.e("reason", reason);
        Log.e("room", room);

    }
}

This might solve your problem.

Sheraz Ahmad Khilji
  • 8,300
  • 9
  • 52
  • 84
0

We missed Thread here:

Just add below code to join group:

private void setChatRoomInvitationListener() {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                MultiUserChat.addInvitationListener(xmppConnection, new InvitationListener() {
                    @Override
                    public void invitationReceived(Connection connection,String room, String inviter, String reason,String unKnown, Message message) {
                        XMPPConnectionUtils.configureChatStandards();
                        MultiUserChat muc = new MultiUserChat(connection, room);
                        try {
                            muc.join("My_Name_Here");
                        } catch (XMPPException e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        });
        thread.start();
    }

Hope this will help a lot.

Hiren Patel
  • 52,124
  • 21
  • 173
  • 151