2

在我的聊天应用程序中,我想实现群聊功能。同样,我想创建房间并将邀请发送给我的朋友加入房间。这是我加入并邀请朋友到房间的代码。

创建房间

//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");



        }
    });

}

为了接收邀请,我在我的服务类中实现了一个邀请监听器。但我无法通过通知收到邀请。代码的问题。

这是我的邀请听众。

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");

请告诉我为什么我没有收到邀请。??

谢谢

4

3 回答 3

2

你写这段代码之后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();
                        }
                    }


                });

它对我有用..试试看

于 2016-09-02T12:42:43.917 回答
0

你可以试试这个

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);

    }
}

这可能会解决您的问题。

于 2012-10-30T04:19:47.987 回答
0

我们在这里错过了线程

只需添加以下代码即可加入群组:

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();
    }

希望这会有所帮助。

于 2015-10-20T09:30:22.597 回答