質問

I am creating a chat application for Gtalk using the asmack api, and i want to get the messages when user goes offline, but gettting problems because of some problems in ServiceDiscoveryManager and its saying that feature not implemented(501) and tried to implements all the things which other users have same problem, but now i m getting this error. I am posting the code and logcat with this. any help appreciated.

 ConnectionConfiguration connConfig = new ConnectionConfiguration(
                    host, Integer.parseInt(port), service);
 connConfig.setSASLAuthenticationEnabled(true);
 connConfig.setSendPresence(false);
 connection = new XMPPConnection(connConfig);
 connection.connect();
 connection.login(username, password);
 ServiceDiscoveryManager sdm= ServiceDiscoveryManager.getInstanceFor(connection);
 mOfflineMessageManager = new OfflineMessageManager(connection);
 offlinemsgs = mOfflineMessageManager.getMessageCount(); 

this is the code where I call for offline messages just after login, and below is the response in logcat error:

03-16 11:26:53.871: W/System.err(325): feature-not-implemented(501)
03-16 11:26:53.881: W/System.err(325):  at org.jivesoftware.smackx.OfflineMessageManager.getMessages(OfflineMessageManager.java:210)
03-16 11:26:53.881: W/System.err(325):  at com.apache.android.xmpp.MainScreen.getOfflinemessages(MainScreen.java:911)
03-16 11:26:53.881: W/System.err(325):  at com.apache.android.xmpp.MainScreen$LogIn.doInBackground(MainScreen.java:612)
03-16 11:26:53.881: W/System.err(325):  at com.apache.android.xmpp.MainScreen$LogIn.doInBackground(MainScreen.java:1)
03-16 11:26:53.881: W/System.err(325):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-16 11:26:53.881: W/System.err(325):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-16 11:26:53.881: W/System.err(325):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-16 11:26:53.881: W/System.err(325):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
03-16 11:26:53.881: W/System.err(325):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
03-16 11:26:53.891: W/System.err(325):  at java.lang.Thread.run(Thread.java:1096)

please help on this, trying to get the solution from many days but cant find any solution.

役に立ちましたか?

解決

try this :

 ConnectionConfiguration connConfig = new ConnectionConfiguration(
                    host, Integer.parseInt(port), service);
 connConfig.setSASLAuthenticationEnabled(true);
 connConfig.setSendPresence(false);
 connection = new XMPPConnection(connConfig);
 connection.connect();
 connection.login(username, password);
 ServiceDiscoveryManager sdm= ServiceDiscoveryManager.getInstanceFor(connection);

////////////////////////////

    OfflineMessageManager offlineManager = new OfflineMessageManager(  
                    Client.getConnection());  
            try {  
                Iterator<org.jivesoftware.smack.packet.Message> it = offlineManager  
                        .getMessages();  
                System.out.println(offlineManager.supportsFlexibleRetrieval());  
                System.out.println("Number of offline messages:: " + offlineManager.getMessageCount());   
                Map<String,ArrayList<Message>> offlineMsgs = new HashMap<String,ArrayList<Message>>();    
                while (it.hasNext()) {  
                    org.jivesoftware.smack.packet.Message message = it.next();  
                    System.out  
                            .println("receive offline messages, the Received from [" + message.getFrom()  
                                    + "] the message:" + message.getBody());  
                    String fromUser = message.getFrom().split("/")[0];  

                    if(offlineMsgs.containsKey(fromUser))  
                    {  
                        offlineMsgs.get(fromUser).add(message);  
                    }else{  
                        ArrayList<Message> temp = new ArrayList<Message>();  
                        temp.add(message);  
                        offlineMsgs.put(fromUser, temp);  
                    }  
                }  
                / / Deal with a collection of offline messages ...  
                Set<String> keys = offlineMsgs.keySet();  
                Iterator<String> offIt = keys.iterator();  
                while(offIt.hasNext())  
                {  
                    String key = offIt.next();  
                    ArrayList<Message> ms = offlineMsgs.get(key);  
                    TelFrame tel = new TelFrame(key);  
                    ChatFrameThread cft = new ChatFrameThread(key, null);  
                    cft.setTel(tel);  
                    cft.start();  
                    for (int i = 0; i < ms.size(); i++) {  
                        tel.messageReceiveHandler(ms.get(i));  
                    }  
                }  
                offlineManager.deleteMessages();  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  

See this Like : http://community.igniterealtime.org

他のヒント

Why u not just use PacketListener i'm using it and getting offline messages .here's my code i'm saving also messages into Sqlite db to get user messages after awhile when he left this chat and chat with another friend and then go back.

PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
            Main.conn.addPacketListener(new PacketListener() {

                public void processPacket(Packet p) {

                    message = (Message) p;// this was the problem

                    if (message.getBody() != null) {
                        messages.add(message.getBody());
                        Log.i("XMPPClient",
                                "Reciveing text [" + message.getBody() + "] ");

                        time.add(TimeDate());

                        // Add the incoming message to the list view
                        mHandler.post(new Runnable() {
                            public void run() {
                                // / saving convertsations into SQLite db
                                try {

                                    save.open();
                                    save.InsertIntoDatabase(jid, messages, time);
                                    messagesDB = save.GetAllValues(Table_Name,
                                            new String[] { "messages" },
                                            friendJid);
                                    timeDB = save.GetAllValues(Table_Name,
                                            new String[] { "time" }, friendJid);
                                    adapter = new ConversationListAdapter(
                                            getApplicationContext(),
                                            messagesDB, timeDB);
                                    list.setAdapter(adapter);
                                    adapter.notifyDataSetChanged();
                                    save.close();

                                } catch (SQLException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }


                            }
                        });
                    }
                }

            }, filter);
        }

I was facing the same problem developing an Android client with aSmack connected to an Openfire server: I simply can't retrive offline messages. So reading the [XEP-0013]: http://www.xmpp.org/extensions/xep-0013.html I figured out why:

"Upon receiving a service discovery request addressed to a node of "http://jabber.org/protocol/offline" (either a disco#info request as in this use case or a disco#items request as in the next use case), the server MUST NOT send a flood of offline messages if the user subsequently sends initial presence to the server during this session. Thus the user is now free to send initial presence (if desired) and to engage in normal IM activities while continuing to read through offline messages."

So, what I learn:

  1. Check if your server support Flexible Offline Message Retrieval XEP-0013;
  2. You must initialize SmackAndroid.init(Context) - See aSmack README;
  3. You must use AndroidConnectionConfiguration instead of ConnectionConfiguration;
  4. You can set your configuration to setSendPresence(true) if you need.

In order to get the things working you must connect, send initial presence as "unavalilable" in order to retrieve your messages, then after that send presence as "available".

Then your code should looks like this (try/catch blocks ommited):

SmackAndroid.init(context);
AndroidConnectionConfiguration connConfig = null;
connConfig = new AndroidConnectionConfiguration(domain, PORT);
connConfig.setSendPresence(true);
connConfig.setReconnectionAllowed(true);
connection = new XMPPConnection(connConfig);
connection.connect();
connection.login("username", "password");

PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
//RECEIVER
connection.addPacketListener(getPacketListener(), filter);
//in order to retrieve offline messages: XEP-0013
connection.sendPacket(new Presence(Presence.Type.unavailable));
connection.sendPacket(new Presence(Presence.Type.available));

Then after send Presence.Type.unavailable packet, all offline messages were sent automaticaly!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top