我想使用此代碼連接到我運行的Openfire服務器:連接到使用Android
public static final String HOST = "ipofmyserver";
public static final int PORT = 9122; // set by me
//public static final String SERVICE = "gmail.com"; not used because i don't know what it refers to
ConnectionConfiguration connConfig = new ConnectionConfiguration(HOST, PORT);
XMPPConnection connection = new XMPPConnection(connConfig);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Connect to the server
try {
connection.connect();
} catch (XMPPException e) {
connection = null;
//Unable to connect to server
}
//Most servers require you to login before performing other tasks.
if (connection != null) {
try {
connection.login("xxxx", "xxxx");
} catch (XMPPException e) {
e.printStackTrace();
}
}
}
logcat的
編輯
我添加了一個exceptionininitializer異常,現在它不會崩潰,但現在我得到一個:
05-07 03:27:55.734 3184-3184/xxx.xxx.xxxxxE/dalvikvm﹕ Could not find class 'javax.naming.directory.InitialDirContext', referenced from method org.jivesoftware.smack.util.dns.JavaxResolver.<clinit>
UPDATE
我讀過的Android只允許一些標準JRE類,這是在這個白名單https://developers.google.com/appengine/docs/java/jrewhitelist
這樣的訪問..如果我想使用Smack API,我應該怎麼做?我不能?我試着用aSmack,但它必須在linux或mac上編譯,而且我只有windows
可能重複(http://stackoverflow.com/questions/23507724/how -to-實現-XMPP的聊天功能於一,Android的應用程序) – Flow