Android的拍击MessageEventListenerAndroid、MessageEventListener

2023-09-06 17:21:23 作者:仅一心 不二情

I'm尝试使用XMPP's消息事件接口。据我了解,你可以标记你发送一个请求交货通知的消息国旗和收件人是不是负责任的向您发送此通知。有没有人成功实施呢?有人可以给我一些示例code?我的code doesn't工作。我的听众(MessageEventNotificationListener,MessageEventRequestListener)的回调从来不被称为:

  @覆盖
公共无效的onCreate(包savedInstanceState)
{
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.chat);

    PacketFilter过滤器=新MessageTypeFilter(Message.Type.chat);
    VajasKifli.connection.addPacketListener(这一点,过滤器);

    电视=(TextView中)findViewById(R.id.textView1);
    tvState =(TextView中)findViewById(R.id.textView2);
    等=(EditText上)findViewById(R.id.editText1);
    et.addTextChangedListener(本);

    纪念品=新MessageEventManager(VajasKifli.connection);
    mem.addMessageEventNotificationListener(本);
    mem.addMessageEventRequestListener(本);

    SDM =新ServiceDiscoveryManager(VajasKifli.connection);
    VajasKifli.log(SDM:+ SDM);

    StateManager的= ChatStateManager.getInstance(VajasKifli.connection);

    收件人= getIntent()getStringExtra(接收方)。
    聊天= VajasKifli.connection.getChatManager()createChat(收件人,chat-+收件人,这一点​​)。
    VajasKifli.log(聊天创建:+聊天);

    。VajasKifli.connection.getChatManager()addChatListener(本);

    SV =(滚动型)findViewById(R.id.scrollView1);

    处理器=新ChatHandler();
}

公共无效onClickSend(查看视图)
{
    字符串文本= et.getText()的toString()。
    如果(text.length()大于0)
    {
        VajasKifli.log(发送文本[+文字+]至[+收件人+]);

        尝试
        {
            消息消息=新的Message();
            message.setBody(文本);
            MessageEventManager.addNotificationsRequests(消息,假的,真的,假的,假的);
            chat.sendMessage(消息);

            stateManager.setCurrentState(ChatState.active,聊天);
            lastState = ChatState.active;
            tv.append(\ñ+ VajasKifli.connection.getUser()replaceFirst(@。*,)+:+文字);
            sv.fullScroll(ScrollView.FOCUS_DOWN);
        }
        赶上(XMPPException E)
        {
            VajasKifli.logError(e.toString());
        }

        // showToast(派:+文字);
    }
}
 

解决方案

您应该得到一个数据包追踪的XMPP连接,或者通过Wireshark的或通过咂嘴调试选项,以保证交付通知真的发送了连接的另一端。如果不是,这可以解释为什么听众不叫。

信息在SMACK事件经已过时 XEP-22 完成。还有的是,对方并没有实现这个不合时宜的机制的好机会。

I´m trying to use XMPP´s message event interface. As far as I understand you can mark a message you send with a 'delivery notification requested' flag and the recipient is than responsible to send you this notification. Has anyone succeeded in implementing this? Can someone send me some sample code? My code doesn´t work. The callbacks of my listeners (MessageEventNotificationListener, MessageEventRequestListener) are never called:

@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 );
    }
}

解决方案

You should get a packet-trace of the XMPP connection, either via wireshark or via the smack debug option, to assure that the delivery notifications are really send by the other end of the connection. If not, this would explain why the listeners aren't called.

Message events in SMACK are done via the now obsolete XEP-22. There is a good chance that the other side does not implement this out-dated mechanism.