Avaya Client SDK

< Back to Package Overview

Using Presence with Shared Contacts

Using the Avaya Client SDK, you can easily get presence of shared contacts.

Subscribe for contact's presence

To subscribe for contact's presence, use functions exposed by Contact class. First, add PresenceSubscriptionListener to Contact by calling the addPresenceListener() method of the Contact class.

PresenceSubscriptionListener presenceSubscriptionListener = 
new PresenceSubscriptionListener() {
    @Override
    public void onPresenceUpdated(Contact contact, Presence presence) {
        Log.d(LOG_TAG, "Overall presence state of " + 
        contact.getNativeDisplayName() + "  is " + presence.getOverallState());
    }
};

contact.addPresenceListener(presenceSubscriptionListener);

Start presence service

After that, call Contact.startPresence(). You will receive instant notification with current presence information of the contact and will be receiving further updates.

contact.startPresence(AccessControlBehavior.NONE, 
new PresenceCompletionHandler() {
    @Override
    public void onSuccess() {
        Log.d(LOG_TAG, "Successfully subscribed for presence updates.");
    }

    @Override
    public void onError(PresenceException e) {
        Log.e(LOG_TAG, "Failed to subscribe for presence updates. " + e);
    }
});

Get contact's presence

Once we subscribed for contact's presence the updates will be reflected automatically. If you need to get contact's presence immediately, call Contact.getPresence().getOverallState() after presence service is started.

PresenceState presenceState = contact.getPresence().getOverallState();

Stop presence service and unsubscribe from updates

Do not forget to unsubscribe from contact's presence when you no longer want to receive the presence updates. First, remove PresenceSubscriptionListener from Contact by calling the removePresenceListener() method of the Contact class. After that, call Contact.stopPresence() to stop presence service.

contact.removePresenceListener(presenceSubscriptionListener);

contact.stopPresence(new PresenceCompletionHandler() {
    @Override
    public void onSuccess() {
        Log.d(LOG_TAG, "Successfully unsubscribed for presence updates.");
    }

    @Override
    public void onError(PresenceException e) {
        Log.e(LOG_TAG, "Failed to unsubscribe for presence updates. " + e);
    }
});