I think you are missing the implementation of auto accepting Group chat joining Request in your code.

Below code is working for AMACK group chat using Openfire Server

1. Creating XMPP Connection

    XMPPTCPConnection connection = new XMPPTCPConnection(config);
    connection.connect();
    connection.login(ID1, password1);
    Presence presence = new Presence(Presence.Type.available);
    connection.sendPacket(presence);

2. Creating Persistant Group Chat Room

    MultiUserChat chatRoom = new MultiUserChat(connection, "room786@conference.dishaserver");
    chatRoom.create("nagarjuna");
    Form form = chatRoom.getConfigurationForm().createAnswerForm();
    form.setAnswer("muc#roomconfig_publicroom", true);
    form.setAnswer("muc#roomconfig_roomname", "room786");
    form.setAnswer("muc#roomconfig_roomowners",owners);
    form.setAnswer("muc#roomconfig_persistentroom", true);
    chatRoom.sendConfigurationForm(form);

3. Sending invitation to ride participants

    MultiUserChat.addInvitationListener(connection, groupChatListener);
    chatRoom.invite("surya@dishaserver", "hi surya");

4. Auto accepting the request of RIDER to join group chat

    public class GroupChatListener implements InvitationListener{
    String nickname;

    public GroupChatListener(String nick)
    {
        nickname = nick;
    }

    @Override
    public void invitationReceived(XMPPConnection con, String room,String inviter, String reason, String password, Message message)
    {
        System.out.println(" Entered invitation handler... ");
        try
        {
            MultiUserChat chatRoom = new MultiUserChat(con, room);
            chatRoom.join(nickname);
        }
        catch (NoResponseException | XMPPErrorException| NotConnectedException e)
        {
            e.printStackTrace();
        } catch (SmackException e)
        {
            e.printStackTrace();
        }
        System.out.println(" Invitation Accepted... ");
    }

}

5. Sending message to group chat members

private static void sendMessageToRoomOccupants(XMPPTCPConnection connection) throws NotConnectedException
{
    Message msg = new Message("room789@conference.dishaserver",Message.Type.groupchat);
    msg.setBody("This is nagarjuna friednds. Please join this room and let us have fun."); connection.sendPacket(msg);
}

6. Receiving the group chat message by ride users

MultiUserChat chatRoom = new MultiUserChat(connection, "room789@conference.dishaserver");
chatRoom.addMessageListener(new GroupChatMsgListener());

package com.disha.test;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.packet.Packet;

public class GroupChatMsgListener implements PacketListener
{

    @Override
    public void processPacket(Packet packet) throws NotConnectedException
    {
        System.out.println(" Received group cht messages... ");
        System.out.println("from : "+packet.getFrom());
        System.out.println("to : "+packet.getTo());
        System.out.println(packet.toString());
    }
}
shareimprove this a


'Android > xmpp' 카테고리의 다른 글

xmpp smack 이용해서 pubsub 등록하기 예제  (0) 2017.01.25
openfire ssl 설정방법  (0) 2017.01.23
XMPP 예제 소스  (0) 2017.01.22
Xmpp 으로 할수 있는 내용 정리  (0) 2017.01.17
Android xmpp  (0) 2017.01.16

+ Recent posts