Unable to change presence status of my user with Smack
Asked Answered
S

2

9

I tried to set online mode but it doesn't work through a Roster. I ran this code and check my localhost server, the mode still "available" and not "Do not disturb".

final Connection connection = new XMPPConnection("xxx.xxx.x.xx");

connection.connect();
connection.login("hieugioi@hieund", "123456");

final Roster roster = connection.getRoster();           
Presence p = roster.getPresence("hieugioi@hieund");
p.setPriority(128);
p.setMode(Mode.dnd);
Stipe answered 18/12, 2012 at 8:57 Comment(0)
P
22

Because you don't send the Presence packet to the server. After you have assembled your Presence packet you need to send it. For example:

Presence p = new Presence(available, "I am busy", 42, Mode.dnd);
connection.sendStanza(p);

See also: Smack - Getting Started; section "Reading and Writing Packets"

Paradis answered 18/12, 2012 at 22:25 Comment(2)
After setting it, I can't get it out. That's the problem. I expect a function like this: connection.getStatus(), connection.getMode();Stipe
hi @Paradis ..I have tried this..But it is showing status of only online users..not for offline users?How to get status of all the offline , online users?Oralee
B
0

With Smack 4.4.4 and Kotlin you can set presence this way (just showing unavailable on disconnect):

if (connection != null){
  var pb=PresenceBuilder.buildPresence().ofType(Presence.Type.unavailable)
  connection!!.sendStanza(pb.build())
}
Bazar answered 22/4 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.