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