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); }});
但我需要表明该消息是用户READ或NOT whatsApp蓝色tickmark,
任何人都可以帮助我,我被击中了.如何实现此消息读取概念.
提前致谢.
@H_419_10@解决方法 创建自定义数据包扩展类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 messagepublic ReadReceipt(String ID){ this.ID = ID;}public String getID(){ return ID;}@OverrIDepublic String getElementname(){ return ELEMENT;}@OverrIDepublic String getnamespace(){ return nameSPACE;}@OverrIDepublic 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")); }}}
当进入聊天列表时发送具有相同包ID的消息标签
Message message = new Message(userJID);ReadReceipt read = new ReadReceipt(messagePacketID);message.addExtension(read);mConnection.sendPacket(sendReadStatus);
其中mConnection是xmmppConnection对象
将数据包扩展添加到消息对象
在连接到服务器之前,将此扩展提供程序添加到ProvIDerManager
ProvIDerManager.getInstance().addExtensionProvIDer(ReadReceipt.ELEMENT,ReadReceipt.nameSPACE,new ReadReceipt.ProvIDer());
创建packetListener类以从接收器接收读取收据
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;}@OverrIDepublic 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); } }
最后添加监听器到你的xmpp连接对象,它成功地工作
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);总结
以上是内存溢出为你收集整理的android – 如何实现消息读取状态,如whatsapp蓝色刻度?全部内容,希望文章能够帮你解决android – 如何实现消息读取状态,如whatsapp蓝色刻度?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)