Get online users (registry entries) using smack 4.1 in android

I am trying to get registry entries using smack 4.1 beta 2 in android.

https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-and-UpgradeGuide Quotes from the link above.

"Now the list now follows the manager template (use Roster.instanceFor to get an instance, not more than XMPPConnection.getRoster)"

First of all, I can’t get the "Roster" object, can the libraries I imported may not have this package or am I missing any lib here?

I use all the libraries mentioned in the link above.

Can someone help me get registry entries using smack 4.1?

thanks

+7
android xmpp smack asmack
source share
2 answers

This is a step-by-step solution that ends (hopefully) by answering your question. You should pay particular attention to importing Java into STEP 2 and the Roster.reloadAndWait () method in STEP 4.

NOTE. . It is recommended that you run the Smack code using AsyncTask .

Step 1. Include the following dependencies. For Android Studio users, this is located in the build.gradle file (Module: app)

dependencies { compile "org.igniterealtime.smack:smack-android:4.1.0-rc1" compile "org.igniterealtime.smack:smack-android-extensions:4.1.0-rc1" compile "org.igniterealtime.smack:smack-tcp:4.1.0-rc1" } 

Also make sure your program has the appropriate permissions for TCP activity. For Android Studio users, you can add this to your AndroidManifest.xml file:

 <uses-permission android:name="android.permission.INTERNET"/> 

Step 2. Import the following

 import org.jivesoftware.smack.roster.*; /*you may have been missing this*/ import org.jivesoftware.smack.*; import org.jivesoftware.smack.tcp.*; import java.util.Collection; /*optional*/ 

Step 3: Connect to the server

 /*Example solution. The exact settings would have to be adjusted outside of practice*/ XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration .builder() .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled) .setServiceName("192.168.2.14") .setHost("192.168.2.14") .setPort(5222) .setCompressionEnabled(false).build(); XMPPTCPConnection connection = new XMPPTCPConnection(conf); try { connection.connect(); connection.login("john","123"); ... 

Step 4: Get List

 ... Roster roster = Roster.getInstanceFor(connection); if (!roster.isLoaded()) roster.reloadAndWait(); Collection <RosterEntry> entries = roster.getEntries(); for (RosterEntry entry : entries) System.out.println("Here: " + entry); 
+22
source share

You can use Smack-xxx-4.1.0-rc5 as shown below:

 smack-android-4.1.0-rc5.jar smack-android-extensions-4.1.0-rc5.jar smack-core-4.1.0-rc5.jar smack-experimental-4.1.0-rc5.jar smack-extensions-4.1.0-rc5.jar smack-im-4.1.0-rc5.jar smack-resolver-minidns-4.1.0-rc5.jar smack-sasl-provided-4.1.0-rc5.jar smack-tcp-4.1.0-rc5.jar 
0
source share

All Articles