QuickBlox Documentation

QuickBlox provides powerful Chat API and SDK to add real-time messaging and video calls to your web and mobile apps. Learn how to integrate QuickBlox across multiple platforms.

Address Book

Learn how to store and sync the phone contact list with QuickBlox.

Address Book API provides an interface to work with the phone address book. Upload it to the server and retrieve already registered QuickBlox users from your address book.

Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.

Before you begin

  1. Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
  2. Configure QuickBlox SDK for your app. Check out our Setup page for more details.
  3. Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.

Upload address book

First of all, you need to upload your address book to the backend. It's a normal practice to do a full upload for the 1st time and then upload new contacts on future app logins.

ArrayList<QBAddressBookContact> contacts = new ArrayList<>();

QBAddressBookContact contact1 = new QBAddressBookContact();
contact1.setName("QuickBlox United States");
contact1.setPhone("14157558221");

contacts.add(contact1);

QBAddressBookContact contact2 = new QBAddressBookContact();
contact2.setName("QuickBlox United Kingdom");
contact2.setPhone("442081337343");

contacts.add(contact2);

QBAddressBookContact contact3 = new QBAddressBookContact();
contact3.setName("QuickBlox Ukraine");
contact3.setPhone("380955868675");

contacts.add(contact3);

QBAddressBookContact contact4 = new QBAddressBookContact();
contact4.setName("QuickBlox India");
contact4.setPhone("916363113628");

contacts.add(contact4);

String UDID = null;
boolean force = false;

QBUsers.uploadAddressBook(contacts, UDID, force).performAsync(new QBEntityCallback<QBAddressBookResponse>() {
    @Override
    public void onSuccess(QBAddressBookResponse qbAddressBookResponse, Bundle bundle) {
        int created = qbAddressBookResponse.getCreatedCount();
        int deleted = qbAddressBookResponse.getDeletedCount();
        int updated = qbAddressBookResponse.getUpdatedCount();
        Map<String, List> rejected = qbAddressBookResponse.getRejectedErrors();
    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val contacts = ArrayList<QBAddressBookContact>()

val contact1 = QBAddressBookContact()
contact1.name = "QuickBlox United States"
contact1.phone = "14157558221"

contacts.add(contact1)

val contact2 = QBAddressBookContact()
contact2.name = "QuickBlox United Kingdom"
contact2.phone = "442081337343"

contacts.add(contact2)

val contact3 = QBAddressBookContact()
contact3.name = "QuickBlox Ukraine"
contact3.phone = "380955868675"

contacts.add(contact3)

val contact4 = QBAddressBookContact()
contact4.name = "QuickBlox India"
contact4.phone = "916363113628"

contacts.add(contact4)

val udid: String? = null
val force = false

QBUsers.uploadAddressBook(contacts, udid, force).performAsync(object : QBEntityCallback<QBAddressBookResponse>{
    override fun onSuccess(qbAddressBookResponse: QBAddressBookResponse?, b: Bundle?) {
        val created = qbAddressBookResponse?.createdCount
        val deleted = qbAddressBookResponse?.deletedCount
        val updated = qbAddressBookResponse?.updatedCount
        val rejected = qbAddressBookResponse?.rejectedErrors
    }

    override fun onError(e: QBResponseException?) {

    }
})
  • You also can edit an existing contact by providing a new name for it.
  • You also can upload more contacts, not just all in one request. They will be added to your address book on the backend. If you want to override the whole address book on the backend just provide force = true option.
  • A device UDID is a unique device identifier. The UDID is used in cases where a user has two or more devices and contacts sync is off. Otherwise, a user has a single global address book. The UDID maximum length is 64 symbols.

📘

- Add a phone number without the + sign to be able to receive a push notification when the user having this phone number becomes available in your application.
- Phone number length should be from 10 to 15 digits.

Retrieve address book

You can retrieve your uploaded address book using the code snippet below.

QBUsers.getAddressBook(null).performAsync(new QBEntityCallback<ArrayList<QBAddressBookContact>>() {
    @Override
    public void onSuccess(ArrayList<QBAddressBookContact> qbAddressBookContacts, Bundle bundle) {

    }

    @Override
    public void onError(QBResponseException e) {

    }
});
QBUsers.getAddressBook(null).performAsync(object : QBEntityCallback<ArrayList<QBAddressBookContact>>{
    override fun onSuccess(qbAddressBookContacts: ArrayList<QBAddressBookContact>?, b: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Update contacts

If you need to update the name or phone number in your address book contacts, you should use the code sample below.

ArrayList<QBAddressBookContact> contactsToUpdate = new ArrayList<>();

QBAddressBookContact contactToUpdate = new QBAddressBookContact();
contactToUpdate.setPhone("380955868675"); // Existing phone number
contactToUpdate.setName("QuickBlox in Ukraine"); // Name to replace in the Server

contactsToUpdate.add(contactToUpdate);

QBUsers.uploadAddressBook(contactsToUpdate, null, false).performAsync(new QBEntityCallback<QBAddressBookResponse>() {
    @Override
    public void onSuccess(QBAddressBookResponse qbAddressBookResponse, Bundle b) {

    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val contactsToUpdate = ArrayList<QBAddressBookContact>()

val contactToUpdate = QBAddressBookContact()
contactToUpdate.phone = "380955868675" // Existing phone number
contactToUpdate.name = "QuickBlox in Ukraine" // Name to replace in the Server

contactsToUpdate.add(contactToUpdate)

QBUsers.uploadAddressBook(contactsToUpdate, null, false).performAsync(object : QBEntityCallback<QBAddressBookResponse>{
    override fun onSuccess(qbAddressBookResponse: QBAddressBookResponse?, b: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Delete contacts

You can delete contacts by using the code snippet below.

ArrayList<QBAddressBookContact> contactsToDelete = new ArrayList<>();

QBAddressBookContact contactToDelete = new QBAddressBookContact();
contactToDelete.setPhone("380950906090"); // Existing phone number
contactToDelete.setIsDestroy(true); //To mark as Deleted

contactsToDelete.add(contactToDelete);

QBUsers.uploadAddressBook(contactsToDelete, null, false).performAsync(new QBEntityCallback<QBAddressBookResponse>() {
    @Override
    public void onSuccess(QBAddressBookResponse qbAddressBookResponse, Bundle b) {

    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val contactsToDelete = ArrayList<QBAddressBookContact>()

val contactToDelete = QBAddressBookContact()
contactToDelete.phone = "380950906090" // Existing phone number
contactToDelete.isDestroy = true //To mark as Deleted

contactsToDelete.add(contactToDelete)

QBUsers.uploadAddressBook(contactsToDelete, null, false).performAsync(object : QBEntityCallback<QBAddressBookResponse>{
    override fun onSuccess(qbAddressBookResponse: QBAddressBookResponse?, b: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Retrieve registered users

Using this request, you can easily retrieve the QuickBlox users - your address book contacts that are already registered in your app, so you can start communicating with these users right away.

String udid = null;
boolean isCompact = false;

QBUsers.getRegisteredUsersFromAddressBook(udid, isCompact).performAsync(new QBEntityCallback<ArrayList<QBUser>>() {
    @Override
    public void onSuccess(ArrayList<QBUser> qbUsers, Bundle bundle) {
        // Successfully Loaded registered contacts
    }

    @Override
    public void onError(QBResponseException e) {
        // Loading Error
    }
});
val udid: String? = null
val isCompact = false

QBUsers.getRegisteredUsersFromAddressBook(udid, isCompact).performAsync(object : QBEntityCallback<ArrayList<QBUser>>{
    override fun onSuccess(qbUsers: ArrayList<QBUser>?, b: Bundle?) {
        // Successfully Loaded registered contacts
    }

    override fun onError(e: QBResponseException?) {
        // Loading Error
    }
})

If the isCompact parameter is true, the server will return only the userId and phone fields of the QBUser model. Otherwise, all fields of the QBUser model will be returned.

Push notification on new contact joined

There is a way to get a push notification when some contact from your Address Book has been registered in the app. You can enable this feature at QuickBlox Dashboard. Just follow Dashboard => YOUR_APP => Users => Settings direction and enable push notifications for new contacts.

enable push notificaiton for a new contact, for android app

Updated 4 months ago


Address Book


Learn how to store and sync the phone contact list with QuickBlox.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.