在android中使用Asmack时出现404错误

时间:2012-02-08 11:41:59

标签: android xmpp smack asmack

在我的应用程序中我正在尝试使用smack库访问在服务器上创建的节点。当我在java中运行代码时它不会给我任何错误。但是当我在那个时候使用android项目尝试相同的时候lo-gin是成功的但是在访问节点时它给了我404错误。

我在构建路径中添加了Asmack jar文件。请帮助我......我被卡住了......

    public class ChatApplicationActivity extends Activity {
    /** Called when the activity is first created. */
    static XMPPConnection connection;
    TextView textView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

      textView=(TextView)findViewById(R.id.textView);

      try {
          ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp", new VCardProvider()); 
            ConnectionConfiguration cc = new ConnectionConfiguration("192.168.1.113", 5222, "192.168.1.113");
            connection = new XMPPConnection(cc);
            connection.connect();
             SASLAuthentication.supportSASLMechanism("PLAIN", 0);
            connection.login("test","test");
            Log.i("debug", "login success");


    //      MySmackClient client=new MySmackClient();
    //        client.login("test1","test1");

          //client.displayBuddyList();

         // CreateNode node = new CreateNode(connection);
         subNode("test@eze-dem-113","testNode5");
         // String talkTo = br.readLine();

          System.out.println("-----");
        //  System.out.println("All messages will be sent to " + talkTo);
          System.out.println("Enter your message in the console:");
          System.out.println("-----\n");
    } catch (XMPPException e) {

        e.printStackTrace();
    }
    }


    public void subNode(String JID,String nodeName)
    {


     PubSubManager mgr = new PubSubManager(connection);
   //    String pubSubAddress = "pubsub." + connection.getServiceName();
   //    PubSubManager manager = new PubSubManager(connection, pubSubAddress);
       try {
          // Get the node
         // Node eventNode = manager.getNode("testNode5");  //i always get error here

          LeafNode node = (LeafNode)mgr.getNode(nodeName);

        node.addItemEventListener(new ItemEventCoordinator());

        node.subscribe(JID);
        } catch (XMPPException e) {

            e.printStackTrace();
        }
    }

    class ItemEventCoordinator  implements ItemEventListener
    {
       int track =0;
        public void handlePublishedItems(ItemPublishEvent items)
        {
           System.out.println("Got Publish:"+track);
            PayloadItem<SimplePayload> item = (PayloadItem<SimplePayload>) items.getItems().get(0);

            SimplePayload payload = item.getPayload();

            String payloadData = payload.toXML();
            System.out.println(payloadData);

        }
    }
}

1 个答案:

答案 0 :(得分:0)

您使用的是什么版本的Smack。我不认为asmack正在被维护,所以它可能与Smack本身不同步。

一个建议是改变

 PubSubManager mgr = new PubSubManager(connection);

表示您注释掉的行

 String pubSubAddress = "pubsub." + connection.getServiceName();
 PubSubManager manager = new PubSubManager(connection, pubSubAddress);

Smack被更改为默认为该pubsub地址,asmack可能没有那个更改。如果使用更明确的构造函数,它将在两种环境中保持一致。