如何获得输入状态通知的XMPP

编程入门 行业动态 更新时间:2024-10-09 23:15:44
本文介绍了如何获得输入状态通知的XMPP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图安装一个X​​MPP聊天应用程序。现在我能够到Gmail之间发送消息到Gmail。我想打字的通知,如用户输入的东西或用户输入,,, 的那样。我使用的是主类和消息监听器类。

I am trying to setup an XMPP chat application. Right now I am able to send messages between gmail to gmail. I want typing notification such as user typed something or user is typing,,, Like that. I am using a main class and a Message listener class.

主类

public class XMPPChatDemoActivity extends Activity { //Object of Custom class MessageListener messageListener = new MessageListenerImpl(); private void setConnection(XMPPConnection connection) { this.connection = connection; ChatManager chatmanager = connection.getChatManager(); Chat newChat = chatmanager.createChat("user@gmail", messageListener); try { newChat.sendMessage("Howdy!"); } catch (XMPPException e) { System.out.println("Error Delivering block"); }

消息监听器类

public class MessageListenerImpl implements MessageListener , ChatStateListener{ @Override public void stateChanged(Chat arg0, ChatState arg1) { // TODO Auto-generated method stub } @Override public void processMessage(Chat arg0, Message arg1) { // TODO Auto-generated method stub System.out.print("here"); if (ChatStateposing.equals(arg1)) { Log.d("Chat State",arg0.getParticipant() + " is typing.."); } else if (ChatState.gone.equals(arg1)) { Log.d("Chat State",arg0.getParticipant() + " has left the conversation."); } else { Log.d("Chat State",arg0.getParticipant() + ": " + arg1.getFrom()); } } }

下面每当user@gmail开始输入一些东西在我们的谈话我需要在登录的消息。但其不来了。它发送消息。

Here whenever user@gmail starts to type something in our conversation I need to get a message in Log. But its not coming. It is sending messages..

我试图在堆栈溢出另一种答案。 How要知道在XMPP的Openfire打字状态使用啪

I tried another answer in stack-overflow. How to know Typing Status in XMPP openfire using Smack

但是从这个我也没有得到解决。请帮我。

But from this also I didn't get a solution. Please help me out.

推荐答案

我终于得到了解决。我需要使用聊天听众一起聊经理,也是我需要在建的的 sendcomposingnotification 的函数的使用。无需使用Messageeventrequestlistener接口或任何其它的自定义类。我加了以下几行,,

finally I got the solution. I need to use chat listener along with chat manager and also I need to use in built sendcomposingnotification function. No need to use Messageeventrequestlistener interface or any other custom class for this. I added the following lines,,

connection.getChatManager().addChatListener(new ChatManagerListener() { @Override public void chatCreated(final Chat arg0, final boolean arg1) { // TODO Auto-generated method stub arg0.addMessageListener(new MessageListener() { @Override public void processMessage(Chat arg0, Message arg1) { // TODO Auto-generated method stub Log.d("TYpe Stat",title[0] + " is typing......"); Toast.makeText(getApplicationContext(),title[0] + " is typing......",Toast.LENGTH_SHORT).show(); } } }); } });

和还需要发送通知这样的..

and also need to send notification like this..

mem.sendComposingNotification(etRecipient.getText().toString(), message.getPacketID()); System.out.println("Sending notification");

其中,MEM被MessageEventManger的类型。 编号:www.igniterealtime/builds/smack/docs/latest/javadoc/org/jivesoftware/smackx/MessageEventManager.html

where mem is type of MessageEventManger. Ref: www.igniterealtime/builds/smack/docs/latest/javadoc/org/jivesoftware/smackx/MessageEventManager.html

更多推荐

如何获得输入状态通知的XMPP

本文发布于:2023-11-28 17:46:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643366.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何获得   状态   通知   XMPP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!