2012-03-18 9 views
1

実際には、問題は私のxmppクライアントが友人の招待状を送信した後に受信者が招待状を承認したこと、openfireサーバーが発信者/招待状の送信者に再度サブスクリプションパケットをプッシュすることです。 IQタグを使用して自動的にフィルタリングし、自動的に承認します。Smack Javaを使用してIQタグを取得する方法は?

しかしPacketListenerで、私は、IQのタグを取得することはできません...

私はこれをどのように行うことができますか?

@Override 
public void processPacket(Packet packet) { 
    Log.i(TAG, "SECOND subscription"); 
    Log.d(TAG, "SECOND: "+packet.toXML()); 
    if (packet instanceof Presence) { 
     Presence p = (Presence) packet; 
     Log.d(TAG, "TYPE-Presence: "+p.getType()); 
     if (p.getType() != Presence.Type.subscribe) 
     return; 
     String from = p.getFrom(); 
     Log.d(TAG, "PACKET from: "+from); 
     Notification notification = new Notification(android.R.drawable.stat_notify_more, mService.getString(
       R.string.AcceptContactRequest, from), System.currentTimeMillis()); 
     notification.flags = Notification.FLAG_AUTO_CANCEL; 
     Intent intent = new Intent(mService, Subscription.class); 
     intent.setData(Contact.makeXmppUri(from)); 
     notification.setLatestEventInfo(mService, from, mService 
       .getString(R.string.AcceptContactRequestFrom, from), PendingIntent.getActivity(mService, 0, 
         intent, PendingIntent.FLAG_ONE_SHOT)); 
     int id = p.hashCode(); 
     mService.sendNotification(id, notification); 
    } 
} 

答えて

3

着信知能指数「がIQTypeFilter」フィルタを用いてフィルタリングすることができます。メソッドを示すサンプルコードです。

connection.connect(); 

    /* packet listener: listen for incoming messages of type IQ on the connection (whatever the buddy) */ 
    PacketFilter filter = new IQTypeFilter(IQ.Type.SET); // or IQ.Type.GET etc. according to what you like to filter. 

    connection.addPacketListener(new PacketListener() { 
     public void processPacket(Packet packet) { 
      // HERE YOU PUT YOUR CODE TO HANDLE THE IQ MESSAGE 
     } 
    }, filter); 
+0

Work Great!ありがとう! – user724861

+0

あなたの答えをちょっと詳しく説明してください。実際に私はIQメッセージをどのように処理するのか分からない –

関連する問題