Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement message read status like whatsapp blue tick mark?

I am developing one application in that chatting is one module, for chatting i am using xmpp. when i am sending message i am getting that message delivery status using DeliveryReceiptManager.

DeliveryReceiptManager.getInstanceFor(connection).enableAutoReceipts();
DeliveryReceiptManager.getInstanceFor(connection).addReceiptReceivedListener(new ReceiptReceivedListener()
{
        @Override
        public void onReceiptReceived(String arg0, String arg1, String arg2)
        {
            Log.v("app", arg0 + ", " + arg1 + ", " + arg2);
        }
});

But i need to show that message is user READ or NOT like whatsApp blue tickmark, Can any one help me i am struck here. how to implement this message read concept.

Thanks in advance.

like image 897
NareshRavva Avatar asked Mar 11 '15 18:03

NareshRavva


People also ask

How do I know my WhatsApp message is read without blue ticks?

When you receive a message on WhatsApp, turn on Airplane mode on your smartphone. This will turn off Wi-Fi and Mobile data on your device. You can now go to WhatsApp and read chat messages. This way the sender will not be notified or shown any blue ticks if you have Read Receipt turned on.

How do you get blue tick on messages?

You can tap on a previous conversation, or tap the "New Message" icon at the top right corner to create a new chat. Type in your message. Tap the send button. When the recipient has read the message, the check marks will turn blue.

Why do some messages on WhatsApp ticks not turn blue?

Missing read receipts If you don't see two blue check marks, a blue microphone, or an “Opened” label next to your sent message or voice message: You or your recipient might have disabled read receipts in the privacy settings.

How do I know my WhatsApp message has been read?

As WhatsApp users, one knows that whenever a text is sent, a single tick mark will appear by it to indicate your message was sent. Two ticks mean your message was delivered, and two blue ticks would mean your message has been read.


1 Answers

create custom packet extension class

public class ReadReceipt implements PacketExtension
{

public static final String NAMESPACE = "urn:xmpp:read";
public static final String ELEMENT = "read";

private String id; /// original ID of the delivered message

public ReadReceipt(String id)
{
    this.id = id;
}

public String getId()
{
    return id;
}

@Override
public String getElementName()
{
    return ELEMENT;
}

@Override
public String getNamespace()
{
    return NAMESPACE;
}

@Override
public String toXML()
{
    return "<read xmlns='" + NAMESPACE + "' id='" + id + "'/>";
}

public static class Provider extends EmbeddedExtensionProvider
{
    @Override
    protected PacketExtension createReturnExtension(String currentElement, String currentNamespace,
            Map<String, String> attributeMap, List<? extends PacketExtension> content)
    {
        return new ReadReceipt(attributeMap.get("id"));
    }
}
}

when enters the chat list send message tag with same packet id like this

Message message = new Message(userJid);
ReadReceipt read = new ReadReceipt(messagePacketID);
message.addExtension(read);
mConnection.sendPacket(sendReadStatus);

where mConnection is xmmppConnection object

add packet extension to message object

add this extension provider to ProviderManager before connecting to server

ProviderManager.getInstance().addExtensionProvider(ReadReceipt.ELEMENT, ReadReceipt.NAMESPACE, new ReadReceipt.Provider());

create packetListener class to receive read receipt from receiver

public class ReadReceiptManager implements PacketListener
    {



  private static Map<Connection, ReadReceiptManager> instances = Collections.synchronizedMap(new WeakHashMap<Connection, ReadReceiptManager>());
    static 
    {
        Connection.addConnectionCreationListener(new ConnectionCreationListener() 
        {
            public void connectionCreated(Connection connection) 
            {
                getInstanceFor(connection);
            }
        });
    }

private Set<ReceiptReceivedListener> receiptReceivedListeners = Collections.synchronizedSet(new HashSet<ReceiptReceivedListener>());

private ReadReceiptManager(Connection connection) 
{
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    sdm.addFeature(ReadReceipt.NAMESPACE);
    instances.put(connection, this);

    connection.addPacketListener(this, new PacketExtensionFilter(ReadReceipt.NAMESPACE));
}

 public static synchronized ReadReceiptManager getInstanceFor(Connection connection) 
 {
    ReadReceiptManager receiptManager = instances.get(connection);

    if (receiptManager == null) 
    {
        receiptManager = new ReadReceiptManager(connection);
    }

    return receiptManager;
}

@Override
public void processPacket(Packet packet) 
{
    ReadReceipt dr = (ReadReceipt)packet.getExtension(ReadReceipt.ELEMENT, ReadReceipt.NAMESPACE);

    if (dr != null) 
    {
        for (ReceiptReceivedListener l : receiptReceivedListeners) 
        {
            l.onReceiptReceived(packet.getFrom(), packet.getTo(), dr.getId());
        }
    }
}

public void addReadReceivedListener(ReceiptReceivedListener listener) {
    receiptReceivedListeners.add(listener);
}

public void removeRemoveReceivedListener(ReceiptReceivedListener listener) {
    receiptReceivedListeners.remove(listener);
  }
 }

finally add listener to your xmpp connection object it works successfully

            ReadReceiptReceivedListener readListener = new ReadReceiptReceivedListener()
                {
                    @Override
                    public void onReceiptReceived(String fromJid, String toJid, String packetId) 
                    {
                        Log.i("Read", "Message Read Successfully");
                    }
                };  
                ReadReceiptManager.getInstanceFor(connection).addReadReceivedListener(readListener);
like image 100
Rakesh Kalashetti Avatar answered Nov 15 '22 20:11

Rakesh Kalashetti