Sushant
Sushant

Reputation: 1282

How to keep chat history locally on android?

I am using openfire and aSmack for my chat application.

I am able to send and receive messages using aSmack library.

Can anyone tell me how to keep these messages in local(android) storage, so that whenever user opens application next time, he can see his previous chat history ? Is there any api provided by aSmack/Smack ?

Upvotes: 2

Views: 1173

Answers (2)

Akshay Paliwal
Akshay Paliwal

Reputation: 3916

use packetListener as:

PacketFilter gc_filter = new MessageTypeFilter(Message.Type.groupchat);

        XMPPconnection.addPacketListener(new PacketListener() 
        {
            public void processPacket(Packet packet) 
            {
                final Message message = (Message) packet;
                String body = message.getBody();
                String from_jid = message.getFrom();
                // save it in data base
            }
        )};

Upvotes: 1

Robin
Robin

Reputation: 24262

Simply register a packet listener and interceptor and log the messages to the backing store of your choice.

Upvotes: 3

Related Questions