如何在android中添加和配置asmack

时间:2013-06-02 15:38:56

标签: asmack

请帮助你分析一下asmack如何在你的机器人中工作。我不能让它为我的应用程序工作。我一直在测试java.lang.verifyError。

1 个答案:

答案 0 :(得分:3)

请务必在libs文件夹中包含最新版本,即asmack-android-17-0.8.3 asmack库。 添加此项可能会删除java.lang.VerifyError

我是按照以下方式进行的,它完美无缺。

public void login(View view)
{
     new Connection().execute("username", "password");
}

private class Connection extends AsyncTask<String, Void, Integer>
{
    private static final int CONNECTION_FAILURE = 0;
    private static final int LOGIN_FAILURE = 1;
    private static final int SUCCESS = 2;

    @Override
    protected Integer doInBackground(String... strings)
    {
        ConnectionConfiguration conConfig = new ConnectionConfiguration("192.168.1.100", 5222, "domain");
        connection = new XMPPConnection(conConfig);
  try
  {
      connection.connect();
      Log.i("AppName", "CONNECTED TO " + connection.getHost());
  }
  catch(Exception e)
  {
      Log.e("AppName", e.getMessage());
      return CONNECTION_FAILURE;
  }
  try
  {
      connection.login(strings[0], strings[1]);
      Log.i("AppName", "LOGGED IN AS " + connection.getUser());
      Presence presence = new Presence(Presence.Type.available);
      connection.sendPacket(presence);
  }
  catch(Exception e)
  {
      Log.e("AppName", e.getMessage());
      return LOGIN_FAILURE;
  }
  return SUCCESS;
    }
}