【问题标题】:Android Simple asmack gmail chatAndroid Simple asmack gmail 聊天
【发布时间】:2014-12-29 14:45:59
【问题描述】:

大家好,标题说明了一切。 我正在使用 asmack-android-8-4.0.6.jar。

代码是:

 //1. connect to server
 ConnectionConfiguration ConnectionConfiguration = new ConnectionConfiguration("gmail.com");

ConnectionConfiguration.setSecurityMode(SecurityMode.required);                
ConnectionConfiguration.setDebuggerEnabled(true);
XMPPConnection connection = new XMPPTCPConnection(ConnectionConfiguration);     

try {   connection.connect();  report+="Connected to server\n"; }
catch (ConnectionException e){ report+=e.toString()+" - (1)\n"; }
catch (SmackException e)     { report+=e.toString()+" - (2)\n"; }
catch (IOException e)        { report+=e.toString()+" - (3)\n"; }
catch (XMPPException e)      { report+=e.toString()+" - (4)\n"; }
tv.setText(report);

 //2. login
 try{   connection.login("myGmailId","MyGmailPwd"); report+="Logged in server\n";}
 catch (SaslException e)  { report+=e.toString()+"\n"; }
 catch (XMPPException e)  { report+=e.toString()+"\n"; }
 catch (SmackException e) { report+=e.toString()+"\n"; }
 catch (IOException e)   { report+=e.toString()+"\n"; }

我无法进入第二部分,因为我已经从第一部分收到以下错误:

org.jivesoftware.smack.SmackException$连接异常(一)

我也配置了proguard

-dontnote org.xbill.DNS.spi.DNSJavaNameServiceDescriptor
-dontwarn org.xbill.DNS.spi.DNSJavaNameServiceDescriptor

# See http://stackoverflow.com/questions/5701126, happens in dnsjava
-optimizations !code/allocation/variable

# Smack specific configuration
-keep class de.measite.smack.AndroidDebugger { *; }
-keep class * implements org.jivesoftware.smack.initializer.SmackInitializer
-keep class * implements org.jivesoftware.smack.provider.IQProvider
-keep class * implements org.jivesoftware.smack.provider.PacketExtensionProvider
-keep class * extends org.jivesoftware.smack.packet.Packet
-keep class org.jivesoftware.smack.ReconnectionManager
-keep class org.jivesoftware.smackx.disco.ServiceDiscoveryManager
-keep class org.jivesoftware.smackx.xhtmlim.XHTMLManager
-keep class org.jivesoftware.smackx.muc.MultiUserChat
-keep class org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager
-keep class org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager
-keep class org.jivesoftware.smackx.filetransfer.FileTransferManager
-keep class org.jivesoftware.smackx.iqlast.LastActivityManager
-keep class org.jivesoftware.smackx.commands.AdHocCommandManager
-keep class org.jivesoftware.smackx.ping.PingManager
-keep class org.jivesoftware.smackx.privacy.PrivacyListManager
-keep class org.jivesoftware.smackx.time.EntityTimeManager
-keep class org.jivesoftware.smackx.vcardtemp.VCardManager
-keep class org.jivesoftware.smack.CustomSmackConfiguration

由于我被困一个月以来,请提供任何帮助。 谢谢 妙招

【问题讨论】:

  • 您好,欢迎来到 StackOverflow!。只是倾倒大量代码并要求“给我答案”并不是很有建设性。当您尝试解释您要完成的工作以及遇到的问题时,您可能会得到更好的答案。
  • 好吧抱歉,我以为我已经说清楚了。我正在尝试使用 eclipse IDE 和 asmack-android-8-4.0.6.jar 在 android 上进行非常基本的聊天。我想连接到 gmail 服务器。我使用上面的代码,但我得到了上面描述的错误。我还能说什么?
  • 你可以用谷歌搜索“Smack ConnectionException”
  • 感谢您的提示。从谷歌搜索我看到我必须添加以下行: Context context = getApplicationContext(); SmackAndroid.init(上下文);但是当我执行程序崩溃并在 logcat 中出现错误时:“找不到从方法 org.jivesoftware.util.dns.dnsjava.DNSJavaResolver.lookupSRVRecord 引用的类 'org.xbill.dns.lookup。请提供其他帮助吗?

标签: android gmail chat asmack


【解决方案1】:

可能有点晚了:

首先,dnsjava lib是否正确添加到项目中? some people forget about this README.

对于 ConnectionException,也许这样的事情会有所帮助:

try
{
 connection.connect();
}
 catch (SmackException e)
{
  Log.i("SmackException ", "ConnectionException: " + e.getMessage());

  List<HostAddress> hostAddresses = ((SmackException.ConnectionException) e).getFailedAddresses();

  if (!hostAddresses.isEmpty())
     {
        Log.i("SmackException: HostAddress: ", hostAddresses.get(0).toString());
        Log.i("SmackException: HostAddress: ", hostAddresses.get(0).getException().toString());
     }

}

【讨论】:

  • 感谢您的帮助,很抱歉我回答迟了。我在 libs 文件夹中添加了 dnsjava-2.1.6.jar。问题是我什至无法从上面的代码中获取信息。这是因为在我必须放置 Context context = getApplicationContext(); 之前,我已经看到它可以正常工作。 SmackAndroid.init(上下文);但如果我这样做,程序就会崩溃!我是世界上唯一一个无法进行简单聊天的人吗?!? :-(
  • 您能提供更多信息吗?也许编辑您的问题并使用 Context 和 SmackAndroid.init() 部分添加代码片段?
猜你喜欢
  • 1970-01-01
  • 2014-06-06
  • 1970-01-01
  • 1970-01-01
  • 2012-06-26
  • 2012-09-01
  • 2012-06-14
  • 1970-01-01
  • 2023-02-15
相关资源
最近更新 更多