4

I'm using Smack and xmpp for sending messages, I created two users in the server OpenFire, created group Friends and added both users on the group.

enter image description here

Now I want to get users from the roster on my phone, I'm using such code for that:

Roster roster = Roster.getInstanceFor(connection);
Collection<RosterEntry> entries = roster.getEntries();
Presence presence;
for (RosterEntry entry : entries) {
    presence = roster.getPresence(entry.getUser());
    Log.e("Users in roster ", entry.getUser());
    Log.e("Name of user in roster ", presence.getType().name());
    Log.e("Status in roster", presence.getStatus());
}

I get entries size zero, so I didn't see in the the log name of the users from roster. Why size of the entries is zero? How to get users from roster? What I'm doing wrong? Both users are online. I can send and get messages from one user to another (so problems with the connection can be excluded).

Also I want to add, that when I check roster in OpenFire, I see user in the roster there:

enter image description here

Here is my build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.example.iryna.smack"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.android.support:appcompat-v7:25.0.1'
    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'
    testCompile 'junit:junit:4.12'
}
Lucky_girl
  • 4,543
  • 6
  • 42
  • 82

0 Answers0