I am able to add Entry to the Xmpp account by using this code. i can't get subscription "both", instead of this i am getting none.
roster.createEntry("[email protected]", "abc", null); 
How to add entry with the presence type=both, when i am subscribing entry to this account. I want to know whether xmpp publish-subscribe functionality ?
EDIT :
public void Addcontact() {    
    Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
    Roster roster = m_connection.getRoster();
    if(!roster.contains("[email protected]")) {        try {           
            roster.createEntry("[email protected]", "pa", null);               
        } catch (XMPPException e) {          
            e.printStackTrace();
        }
    }else {
        Log.i("Acc = ", "contains");
    }
}
I am adding entry like this still i am getting Presence Type = none..
Here is how I add another friend in 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 {
                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 essential part
Presence response = new Presence.Type.subscribed);
response.setTo(address);
sendPacket(response);
Roster roster = mConnection.getRoster();
roster.createEntry(address, name, groups);
In order to listen to incoming request, register addPacketListener to 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 right order:
Another SO question you can check
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With