我正在尝试使用xmpp的消息事件接口。据我所知,您可以将您发送的邮件标记为“已请求传递通知”,收件人有责任向您发送此通知。有人成功地实现了这一点吗?有人能寄给我一些样本代码吗?我的代码不起作用。从不调用侦听器(MessageEventNotificationListener、MessageEventrequestListener)的回调:
@Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.chat );
PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
VajasKifli.connection.addPacketListener( this, filter );
tv = ( TextView ) findViewById( R.id.textView1 );
tvState = ( TextView ) findViewById( R.id.textView2 );
et = ( EditText ) findViewById( R.id.editText1 );
et.addTextChangedListener( this );
mem = new MessageEventManager( VajasKifli.connection );
mem.addMessageEventNotificationListener( this );
mem.addMessageEventRequestListener( this );
sdm = new ServiceDiscoveryManager( VajasKifli.connection );
VajasKifli.log( "sdm: " + sdm );
stateManager = ChatStateManager.getInstance( VajasKifli.connection );
recipient = getIntent().getStringExtra( "recipient" );
chat = VajasKifli.connection.getChatManager().createChat( recipient, "chat-" + recipient, this );
VajasKifli.log( "chat created: " + chat );
VajasKifli.connection.getChatManager().addChatListener( this );
sv = ( ScrollView ) findViewById( R.id.scrollView1 );
handler = new ChatHandler();
}
public void onClickSend( View view )
{
String text = et.getText().toString();
if( text.length() > 0 )
{
VajasKifli.log( "sending text [" + text + "] to [" + recipient + "]" );
try
{
Message message = new Message();
message.setBody( text );
MessageEventManager.addNotificationsRequests( message, false, true, false, false );
chat.sendMessage( message );
stateManager.setCurrentState( ChatState.active, chat );
lastState = ChatState.active;
tv.append( "\n" + VajasKifli.connection.getUser().replaceFirst( "@.*", "" ) + ": " + text );
sv.fullScroll( ScrollView.FOCUS_DOWN );
}
catch( XMPPException e )
{
VajasKifli.logError( e.toString() );
}
//showToast( "sent: " + text );
}
}
最佳答案
您应该通过wireshark或smack debug选项获得xmpp连接的数据包跟踪,以确保传递通知确实是由连接的另一端发送的。如果没有,这将解释为什么没有调用侦听器。
smack中的消息事件是通过现在已经过时的XEP-22完成的。很有可能对方没有实施这一过时的机制。
关于android - Android Smack MessageEventListener,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7241444/