xmpp send and receive message in android applicati

2019-08-04 05:20发布

问题:

I am working on a sms application. I am able to send a message from my application using the function sendMessage("subject" , "to");. I need to know how to receive the message sent from the other end. I need to get that data and display the data in textview in my application. How can i achive that. How can i achive that. Please guide me.

Thanks in aadvance.

回答1:

this will help you:

 PacketFilter filter = new MessageTypeFilter(Message.Type.chat);

                // Listener for incoming message from any user

                connection.addPacketListener(new PacketListener() {
                    public void processPacket(Packet packet) {
                        final Message message = (Message) packet;
                        if (message.getBody() != null) {
                            fromName = StringUtils.parseBareAddress(message
                                    .getFrom());
                            Log.i("XMPPClient", "Got text [" + message.getBody()
                                    + "] from [" + fromName + "]");     


                                    }
                                }
                            });

                        }
                    }
                }, filter);


标签: android xmpp