Android简单的asmack gmail聊天
大家好,标题说明了一切。 我正在使用asmack-android-8-4.0.6.jar 代码是:Android简单的asmack gmail聊天,android,gmail,chat,asmack,Android,Gmail,Chat,Asmack,大家好,标题说明了一切。 我正在使用asmack-android-8-4.0.6.jar 代码是: //1. connect to server ConnectionConfiguration ConnectionConfiguration = new ConnectionConfiguration("gmail.com"); ConnectionConfiguration.setSecurityMode(SecurityMode.required); Co
//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$连接异常1
我还将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
我已经困了一个月了,请帮忙。
塔克斯
帕特里克可能会晚一点: 首先,dnsjava库是否正确添加到项目中 对于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());
}
}大家好,欢迎来到StackOverflow!。仅仅是扔掉大量代码并问‘给我答案’并不是很有建设性。当你试图解释你想要完成什么,遇到什么问题时,你可能会得到更好的答案。好的,对不起,我想我已经说清楚了。我试图用EclipseIDE和asmack-android-8-4.0.6.jar在android上进行一次非常基本的聊天。我想连接到gmail服务器。我使用上面的代码,但是我得到了上面描述的错误。我还能说什么呢?你可以在谷歌上搜索Smack ConnectionException可能是Thanx的复制品来获取提示。通过谷歌搜索,我看到我必须添加以下行:Context Context=getApplicationContext;SmackAndroid.initcontext;但是当我执行此操作时,程序崩溃,并且在logcat中出现错误:找不到从方法org.jivesoftware.util.dns.dnsjava.DNSJavaResolver.lookupSRVRecord引用的类“org.xbill.dns.lookup”。还有什么需要帮助的吗?谢谢你的帮助,很抱歉我回答得太晚了。我在libs文件夹中添加了dnsjava-2.1.6.jar。问题是我甚至无法从上面的代码中获取信息。这是因为我已经看到,在我必须将Context=getApplicationContext;SmackAndroid.initcontext;但是如果我那样做,程序就会崩溃!我是世界上唯一一个不能进行简单聊天的人吗-你能提供更多的信息吗?也许可以编辑您的问题并添加带有上下文和SmackAndroid.init部分的代码snipet?