Android Smack MessageEventListener

标签 android xmpp smack

我正在尝试使用 XMPP 的消息事件接口(interface)。据我了解,您可以使用“请求送达通知”标志标记您发送的消息,然后收件人负责向您发送此通知。有没有人成功实现这个?有人可以给我一些示例代码吗?我的代码不起作用。我的监听器(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 调试选项获得 XMPP 连接的数据包跟踪,以确保传送通知确实是由连接的另一端发送的。如果不是,这将解释为什么不调用监听器。

SMACK 中的消息事件是通过现已过时的 XEP-22 完成的.很有可能对方没有实现这种过时的机制。

关于Android Smack MessageEventListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7241444/

相关文章:

mysql - 无法在 openfire mysql 数据库中创建表

xmpp - 使用 smack 创建 MUC

java - Smack Presence 不起作用

android - 如何动态排序可排序 TableView 库中的列?

java - SQlite 删除功能不删除条目

android - 如何在 Android 应用程序被杀死之前执行代码

android - 在 Android 中 react native 多包

android - 无法向 GCM CCS 服务器进行身份验证

android - aSmack MUC : Get list of joined rooms after reconnection

java - 在带有 aSmack 的 XMPP 中使用 UserSearch 时,getSearchForm 返回 null