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.*; import org.jivesoftware.smack.*; import org.jivesoftware.smack.tcp.*; import java.util.Collection;
Step 3: Connect to the server
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);
Siege
source share