0
votes

I am building a chat application with open fire server and asmack in android. I am connecting to open fire server with 2 users (lets A & B) from emulator and another 1 user (Lets C) from spark.

Also, I added roster listener for any changes in the user presence value.

So when the app is listening to roster updates, presence.getstatus value for users from emulator (i.e. from asmack api) is coming as null. But I am getting the status value for users who are from spark.

Below is the code implemented for presence changes.

public void presenceChanged(Presence presence) {


            String Name="",Status="";
            Log.d(TAG, "Presence value = "+presence);
            Log.d(TAG, "Presence getfrom value = "+presence.getFrom());
            Log.d(TAG, "Presence getstatus value = "+presence.getStatus());
            Log.d(TAG, "Presence getto value = "+presence.getTo());

below is the log for user from spark.

Presence value = available (Online)
Presence getfrom value = swathi@btp121374/Spark 2.6.3
Presence getstatus value = Online
Presence getto value = kpvsrkp@btp121374

and below is the log for user from asmack android.

Presence value = available
Presence getfrom value = ganesh@btp121374/Smack
Presence getstatus value = null
Presence getto value = kpvsrkp@btp121374

so the problem here is why the presence.getStatus() for asmack user is coming as null.

Presence getstatus value = null

Can someone please tell what else i need to do to get the presence.getStatus() value for asmack users.

2
Which aSmack version? Try enabling SmackConfiguration.DEBUG and see if the presence stanza received by Smack contains a status.Flow
I am using this asmack-android-4.jar. Now I am able to get the status from asmack by setting the presence once connection to openfire is done. Is it really needed?kavuru
I don't now asmack-android-4.jar, are you sure that there is no minor version and patch level version in the jar name?Flow

2 Answers

0
votes

Get presence using this function Presence mPresence = YourXmppConnection .getRoster().getPresence(Userjid); mPresence.getType() gives the availability of user. Check it against Presence.Type.available

0
votes
new AsyncTask<Object,Object,Object>(){

    @Override
    protected Object doInBackground(Object[] params) {
        Presence availability1=roster.getPresence("[email protected]");
        return availability1;
    }

    @Override
    protected void onPostExecute(Object object) {
        super.onPostExecute(object);
        Presence data=(Presence)object;
        Log.d("Presence-----","Presence========>>"+data.getStatus());
        sendBroadCast(""+data.getStatus());
    }
}.execute();