我正在尝试制作一个使用 XMPP 将消息发送到 gmail 帐户的应用程序。我找到了一个提到 Google XMPP 服务器名称的链接,但我认为我无法建立连接。
编辑我更改了服务器的名称,我相信它能够建立连接。但它说名册有 0 个条目。我正在尝试使用 gmail 帐户登录。我得到的新异常:
07-05 14:02:05.099: W/System.err(13903): java.security.KeyStoreException: java.security.NoSuchAlgorithmException: KeyStore jks implementation not found
07-05 14:02:05.099: W/System.err(13903): at java.security.KeyStore.getInstance(KeyStore.java:119)
07-05 14:02:05.099: W/System.err(13903): at org.jivesoftware.smack.ServerTrustManager.<init>(ServerTrustManager.java:70)
07-05 14:02:05.099: W/System.err(13903): at org.jivesoftware.smack.XMPPConnection.proceedTLSReceived(XMPPConnection.java:824)
07-05 14:02:05.099: W/System.err(13903): at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:267)
07-05 14:02:05.099: W/System.err(13903): at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)
07-05 14:02:05.099: W/System.err(13903): at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)
07-05 14:02:05.099: W/System.err(13903): Caused by: java.security.NoSuchAlgorithmException: KeyStore jks implementation not found
07-05 14:02:05.099: W/System.err(13903): at org.apache.harmony.security.fortress.Engine.notFound(Engine.java:177)
07-05 14:02:05.099: W/System.err(13903): at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:151)
07-05 14:02:05.099: W/System.err(13903): at java.security.KeyStore.getInstance(KeyStore.java:116)
07-05 14:02:05.099: W/System.err(13903): ... 5 more
这是原来的例外:
07-05 13:30:23.444: W/System.err(12434): at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:306)
07-05 13:30:23.454: W/System.err(12434): at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
07-05 13:30:23.454: W/System.err(12434): at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:76)
07-05 13:30:38.229: D/Smack(12434): Start Login
07-05 13:30:43.235: E/Smack(12434): Error: No response from the server.
07-05 13:30:43.235: W/System.err(12434): No response from the server.:
07-05 13:30:43.235: W/System.err(12434): at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:58)
07-05 13:30:43.235: W/System.err(12434): at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:232)
07-05 13:30:43.245: W/System.err(12434): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:341)
07-05 13:30:43.245: W/System.err(12434): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:301)
07-05 13:30:43.255: W/System.err(12434): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:283)
07-05 13:30:43.255: W/System.err(12434): at com.example.xmpp.MessageTask.doInBackground(MessageTask.java:33)
07-05 13:30:43.255: W/System.err(12434): at com.example.xmpp.MessageTask.doInBackground(MessageTask.java:1)
07-05 13:30:43.265: W/System.err(12434): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-05 13:30:43.265: W/System.err(12434): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-05 13:30:43.275: W/System.err(12434): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-05 13:30:43.275: W/System.err(12434): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-05 13:30:43.275: W/System.err(12434): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-05 13:30:43.285: W/System.err(12434): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-05 13:30:43.285: W/System.err(12434): at java.lang.Thread.run(Thread.java:856)
这是我的代码:
ConnectionConfiguration config = new ConnectionConfiguration("xmpp.l.google.com", 5222);
XMPPConnection connection = new XMPPConnection(config);
try {
Log.d("Smack", "Start Connect");
connection.connect();
Log.d("Smack", "Start Login");
connection.login(user, pwd);
Roster roster = connection.getRoster();
//Get all rosters
Collection<RosterEntry> entries = roster.getEntries();
//loop through
Log.d("Smack", "Start Rosters");
for (RosterEntry entry : entries) {
//example: get presence, type, mode, status
Presence entryPresence = roster.getPresence(entry.getUser());
String status = entryPresence.getStatus();
Toast.makeText(context, status, Toast.LENGTH_LONG).show();
Log.d("Smack", "Print rosters");
}
Log.d("Smack", "End Rosters");
} catch (XMPPException e) {
// TODO Auto-generated catch block
Log.e("Smack", "Error: " + e.getMessage());
e.printStackTrace();
}