I am trying to make a simple Java client that uses tls to connect to and log into a ejabberd server. I use Android Studio or Eclipse.
I want a simple example that works.
First you have to include the library to your project like this in gradle file:
Add SMACK API to android project by adding dependencies in build.gradle for the app.
compile 'org.igniterealtime.smack:smack-android:4.1.4'
// Optional for XMPPTCPConnection
compile 'org.igniterealtime.smack:smack-tcp:4.1.4'
// Optional for XMPP-IM (RFC 6121) support (Roster, Threaded Chats)
compile 'org.igniterealtime.smack:smack-im:4.1.4'
// Optional for XMPP extensions support
compile 'org.igniterealtime.smack:smack-extensions:4.1.4'
Then connect like this:
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword(userName, passWord);
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
configBuilder.setResource("Android");
configBuilder.setServiceName(DOMAIN);
configBuilder.setHost(HOST);
configBuilder.setPort(PORT);
//configBuilder.setDebuggerEnabled(true);
connection = new XMPPTCPConnection(configBuilder.build());
connection.addConnectionListener(connectionListener);
Hope it will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.