安卓Smack消息事件监听器

3

我正在尝试使用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 );
    }
}

请问您能分享一下您是如何解决这个问题的吗? - Hunt
2个回答

2
你应该通过Wireshark或Smack调试选项获取XMPP连接的数据包跟踪,以确保交付通知确实是由连接的另一端发送的。如果不是,这就解释了为什么监听器没有被调用。
SMACK中的消息事件是通过现已过时的XEP-22完成的。很有可能对方没有实现这个已过时的机制。

0

这太令人困惑了。现在我使用DefaultPacketExtension并发送我需要的事件给自己。这更加简单,易于理解且有效。


请问您是否已经找到了任何 @cuda 的解决方案? - Roster
请问您能否详细说明或分享一下您是如何实现的,谢谢。 - Sathish Gadde

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接