xmppsmack

Unable to change presence status of my user with Smack


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);

Solution

  • 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"