使用XMPP的Android聊天应用程序

时间:2013-12-18 20:51:12

标签: android facebook xmpp chat

我正在尝试设置Android Facebook聊天应用。 我已经使用XMPP权限实现了Facebook登录。

现在,如果我只想测试我的asmack.jar的基本连接设置,我会收到此错误

12-18 21:29:48.845: E/AndroidRuntime(5516): FATAL EXCEPTION: main
12-18 21:29:48.845: E/AndroidRuntime(5516): java.lang.NoClassDefFoundError: org.jivesoftware.smack.ConnectionConfiguration
12-18 21:29:48.845: E/AndroidRuntime(5516): at com.example.messenger.MainActivity.testXMPP(MainActivity.java:68)

这是我的代码。 我希望有人可以提供帮助。 (错误是在TestXMPP中引起的)

package com.example.messenger;
import java.util.Arrays;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.facebook.*;
import com.facebook.Session.StatusCallback;
import com.facebook.widget.LoginButton;

public class MainActivity extends FragmentActivity {
    TextView TV1,TV2;
    Button B1,B2;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    TV1 = (TextView) findViewById(R.id.textView1);
    TV2 = (TextView) findViewById(R.id.textView2);
    B1 = (Button) findViewById(R.id.button1);
    B2 = (Button) findViewById(R.id.button2);

    LoginButton authButton = (LoginButton) findViewById(R.id.authButton);

    authButton.setReadPermissions(Arrays.asList("read_friendlists","xmpp_login"));

    StatusCallback btn_callback = authButton.getSessionStatusCallback();

     B1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
         String text3= "asdfasf";

         Session act_session = Session.getActiveSession(); 
         text3 = act_session.getPermissions().get(0)+act_session.getPermissions().get(1);

         TV1.setText(text3);
        }
      });
      B2.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            try {
                testXMPP();
            } catch (Exception e) {
                // TODO Auto-generated catch block
            TV2.setText(e.toString());
            }
        }
      });

  }

  public void testXMPP()throws XMPPException{

      ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222);
      config.setSASLAuthenticationEnabled(true);
      config.setSecurityMode(SecurityMode.required);
      config.setRosterLoadedAtLogin(true);
      config.setTruststorePath("/system/etc/security/cacerts.bks");
      config.setTruststorePassword("changeit");
      config.setTruststoreType("bks");
    //XMPPConnection xmpp = new XMPPConnection(config);

  }

  private static final String TAG = "MainFragment";

  private Session.StatusCallback callback = new Session.StatusCallback() {
      @Override
      public void call(Session session, SessionState state, Exception exception) {

      }
  };

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      Session.getActiveSession()
          .onActivityResult(this, requestCode, resultCode, data);
  }
}

1 个答案:

答案 0 :(得分:0)

将asmack库放在libs文件夹中。