编程语言
首页 > 编程语言> > android – 无法使用asmack api为Gtalk应用程序获取脱机消息

android – 无法使用asmack api为Gtalk应用程序获取脱机消息

作者:互联网

我正在使用asmack api为Gtalk创建一个聊天应用程序,我希望在用户离线时获取消息,但是由于ServiceDiscoveryManager中的一些问题而导致问题,并且说该功能未实现(501)并试图实现所有其他用户有同样问题的东西,但现在我得到这个错误.我发布代码和logcat与此.任何帮助赞赏.

 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(); 

这是我在登录后立即调用离线消息的代码,下面是logcat错误中的响应:

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)

请帮助解决这个问题,试图从很多天来获得解决方案,但无法找到任何解决方案.

解决方法:

试试这个 :

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

看到这样:http://community.igniterealtime.org

标签:android,google-talk,asmack
来源: https://codeday.me/bug/20190613/1233902.html