How to add and sign a jabber account to my XMPP account?

I can add Entry to my Xmpp account using this code. I can’t get a β€œboth” subscription, instead I get none .

roster.createEntry(" abc@xyz.com ", "abc", null);

How to add an entry with the presence of type=both when I sign up for an entry in this account. I want to know if there is xmpp publish-subscribe functionality?

  • How to receive notifications about incoming presence?
  • How to send notifications about incoming presence?

EDIT:

 public void Addcontact() { Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual); Roster roster = m_connection.getRoster(); if(!roster.contains(" pa@ace.com ")) { try { roster.createEntry(" pa@ace.com ", "pa", null); } catch (XMPPException e) { e.printStackTrace(); } }else { Log.i("Acc = ", "contains"); } } 

I am adding a record as it is still I get Presence Type = none ..

+7
source share
1 answer

This is how I add another friend to my application.

 protected void doAddContactToListAsync(String address, String name, ContactList list) throws ImException { debug(TAG, "add contact to " + list.getName()); Presence response = new Presence.Type.subscribed); response.setTo(address); sendPacket(response); Roster roster = mConnection.getRoster(); String[] groups = new String[] { list.getName() }; if (name == null) { name = parseAddressName(address); } try { // final String name = parseAddressName(address); // Log.v(tag, msg) roster.createEntry(address, name, groups); // If contact exists locally, don't create another copy Contact contact = makeContact(name, address); if (!containsContact(contact)) notifyContactListUpdated(list, ContactListListener.LIST_CONTACT_ADDED, contact); else debug(TAG, "skip adding existing contact locally " + name); } catch (XMPPException e) { throw new RuntimeException(e); } } 

Just use the important part

 Presence response = new Presence.Type.subscribed); response.setTo(address); sendPacket(response); Roster roster = mConnection.getRoster(); roster.createEntry(address, name, groups); 

To listen to an incoming request, register addPacketListener with your connection.

  mConnection.addPacketListener(new PacketListener() { @Override public void processPacket(Packet packet) { Presence presence = (Presence) packet; if (presence.getType() == Type.subscribe) { debug(TAG, "sub request from 1" + address); //Implement accept or reject depend on user action. mContactListManager.getSubscriptionRequestListener() .onSubScriptionRequest(contact); //or you can test with send back Presence.subscribe first and send Presence.subscribed back to requester. } else {// Handle other Presence type. int type = parsePresence(presence); debug(TAG, "sub request from " + type); contact.setPresence(new Presence(type, presence.getStatus(), null, null, Presence.CLIENT_TYPE_DEFAULT)); } } }, new PacketTypeFilter(Presence.class)); mConnection.connect(); 

The correct order is:

  • User1 send Subscribe to user2.
  • User2 sends a subscription and subscribes to user1.
  • Transfer User1 Subscribed to user2.

Another SO question you can check

+12
source

All Articles