Mesibo Phone Contacts Monitoring and Synchronization

In the previous section, we covered the basic phone contacts APIs. Now, we will discuss the mesibo APIs for synchronizing phone contacts and monitoring contact changes. The phone contact synchronization API uses mesibo contact syncronization APIs internally and hence familaize yourself with it before reading further.

Why Phone Contacts Synchronization is important?

Contact synchronization is important for several reasons:

  • If your app logs in users based on their phone number, syncing contacts allows identifying which of the user's contacts are also using your app. This facilitates connecting users with their contacts seamlessly.

  • Popular messaging apps like Telegram and WhatsApp sync contacts to notify users when their contacts start using the app. This enables easy communication.

  • Syncing contacts across devices allows users to access their contacts from any device or browser when using your app. This is useful for multi-device login and web apps.

Phone Contacts Synchronization

Synchronization works by monitoring changes to the device contacts, sending those changes to mesibo cloud or on-premise server, matching user addresses, fetches their profile and subscribing to future updates. For matching to work properly, the contacts and the user address should have the same format.

Phone contact sync uses mesibo's own contact synchronization APIs under the hood. While you can build your own sync logic using native Android and iOS APIs, it can get complicated. Phone address books often have hundreds or thousands of contacts, and contacts frequently change as users sync across devices and cloud services. This makes smooth, battery-efficient sync tricky. Mesibo's APIs handle these complexities across Android and iOS versions in a robust manner. So for most use cases, it's best to leverage mesibo's contact sync instead of reinventing the wheel.

Your app can synchronize all phone contacts in just one line of the code

phoneManager.start(true);

For more granular control, applications can implement a MesiboPhoneContactsListener to receive callbacks for each change and decide whether to synchronize it, as elaborated in the subsequent sections. Additionally, apps can configure various options, which will be explained below and in the following section.

Phone Contacts Listener

Mesibo offers a listener called MesiboPhoneContactsListener, which enables fine-grained control over the contact synchronization process. This listener triggers when changes are detected, allowing apps to choose whether to continue synchronization, modify the synchronization, or ignore it as needed.

To set the listener in your app, you can use the following code:

phoneManager.setListener(contactsListener);

This listener has three functions:

Mesibo_onPhoneContactsChanged

This function is called when mesibo's API detects a change in contacts. You can return true to proceed with synchronization or false to disregard the changes.

boolean Mesibo_onPhoneContactsChanged(){

    return true;
}

Mesibo_onPhoneContactsAdded

This function is triggered when mesibo's API identifies the addition of one or more contacts. You can return true to continue synchronization. Additionally, you have the option to modify the phoneNumbers array before returning true to synchronize specific or modified contacts. Alternatively, you can return false to ignore the changes.

boolean Mesibo_onPhoneContactsAdded(String[] phoneNumbers){


    return true;
}

Mesibo_onPhoneContactsDeleted

This function activates when mesibo's API detects the deletion of one or more contacts. Like the previous functions, you can return true to proceed with synchronization, modify the phoneNumbers array, or return false to ignore the changes.

boolean Mesibo_onPhoneContactsDeleted(String[] phoneNumbers){


    return true;
}

Synchronization Options

The API provides options to filter contacts by type (mobile, landline, etc.) and validity before synchronization. By default, it synchronizes mobile, landline, toll-free, and unknown number types but excludes VoIP, premium, and private numbers. Applications can explicitly include or exclude valid, invalid, and uncertain numbers according to their requirements.

These options can be configured before initiating synchronization.

Type of Phone Numbers to Synchronize

Mesibo can accurately detect the type of phone numbers (e.g., mobile, landline). You can specify which types of phone numbers to sync by calling the appropriate functions with true or false. For example:

phoneManager.syncMobileNumbers(true);
phoneManager.syncLandlineNumbers(true);
phoneManager.start(true);

The complete list of functions for configuring phone number types is as follows:

FunctionDescriptionDefault
syncMobileNumbersSync mobile numberstrue
syncLandlineNumbersSync landline numberstrue
syncTollfreeNumbersSync tollfree numberstrue
syncPremiumNumbersSync premium numbersfalse
syncVoipNumbersSync number used by VoIP servicesfalse
syncPrivateNumbersSync private numbersfalse
syncUnknownNumbersSync numbers whose types were not identified.true

Additionally, you can use the following functions to include or exclude numbers that passed or failed validation:

FunctionDescriptionDefault
syncValidNumbersSync valid numberstrue
syncPossiblyValidNumbersSync numbers for which validity or invalidity is uncertainfalse
syncInvalidNumbersSync invalid numbersfalse

In the next section, we will describe a few utility functions.