【发布时间】:2023-03-26 18:20:02
【问题描述】:
我正在尝试使用以下代码连接到我正在运行的 Openfire 服务器:
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
编辑
我添加了一个异常初始化程序异常,现在它没有崩溃,但现在我得到了:
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>
更新
我了解到 Android 只允许访问某些标准 JRE 类,这些类在此白名单 https://developers.google.com/appengine/docs/java/jrewhitelist
所以.. 如果我想使用 Smack api 应该怎么做?我不能?我试过用aSmack,但它必须在linux或mac上编译,而且我只有windows
【问题讨论】:
标签: java android xmpp openfire