XMPP aSmack - How can I get the current user state (offline/online/away/etc.)?

前端 未结 5 2128
自闭症患者
自闭症患者 2020-12-08 15:54

I am new to xmpp/asmack in android.

Can anyone please help me in getting the presence of the user\'s friends ( roster list)

I am using this :



        
5条回答
  •  猫巷女王i
    2020-12-08 16:49

    As my experience before you can see status and other from Presence you need to subscribe the user.

    for example: user A want to see status and available status from user B, in this case, user A need to subscribe user B. after that user A can see the user B Presence.

    Subscribe Code

    try {
                roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
                String userName = responders.getUsers().get(i).getUsername();
                roster.createEntry("userB@domain", userName, null);
                Presence pres = new Presence(Presence.Type.subscribe);
                pres.setFrom("userA@domain");
                connection.sendStanza(pres);
            } catch (Exception e) {
                android.util.Log.e("tag", "unable to add contact: ", e);
            }
    

提交回复
热议问题