Essential Kit Tutorials
DocumentationDownload
Latest(v3)
Latest(v3)
  • Introduction
  • Features Overview
  • Whats new in v3
    • Version 3 vs Version 2
    • Release Notes
    • Upgrade from V2
  • Plugin Overview
    • Settings
    • Folder Structure
    • Installation FAQ
    • Upgrade Guide
  • Features
    • 📒Address Book
      • Setup
      • Usage
      • Testing
      • FAQ
    • App Shortcuts
      • Setup
      • Usage
    • 🆕App Updater
      • Setup
      • Usage
      • Testing
    • 💲Billing Services
      • Setup
        • iOS
        • Android
      • Usage
      • Testing
        • iOS
        • Android
      • FAQ
    • ☁️Cloud Services
      • Setup
        • iOS
        • Android
      • Usage
      • Testing
      • FAQ
    • 🔗Deep Link Services
      • Setup
        • iOS
        • Android
      • Usage
      • Testing
      • FAQ
    • 🛠️Utilities (Extras)
      • Usage
    • 💯Game Services
      • Setup
        • iOS
        • Android
      • Usage
      • FAQ
    • 📸Media Services
      • Setup
      • Usage
      • FAQ
    • 📆Native UI
      • Setup
      • Usage
      • FAQ
      • Examples
        • Login Dialog
    • Network Services
      • Setup
      • Usage
      • FAQ
    • ⏰Notification Services
      • Setup
        • iOS
        • Android
      • Usage
      • Examples
        • Nudge to come-back to the game
      • FAQ
    • ⭐Rate My App
      • Setup
      • Usage
      • FAQ
    • 🤝Sharing
      • Setup
      • Usage
        • Message Composer
        • Mail Composer
        • Social Share Composer
        • Share Sheet
      • FAQ
      • Examples
        • Add Attachment Example
    • Task Services
      • Setup
      • Usage
    • 🌏Web View
      • Setup
      • Usage
      • FAQ
      • Examples
        • Loading Pdf File
  • Notes
    • Resolving Android Gradle Build Errors
    • Google Play Services Authentication
    • Target API Level vs Min API Level
    • Handling Refunds for In-App Purchases (Billing Services)
Powered by GitBook
On this page
  • Get Contacts Access Status
  • Read Contacts

Was this helpful?

Edit on GitHub
  1. Features
  2. Address Book

Usage

Address Book allows access to contacts on mobile devices.

This feature allows you to read the contacts saved on the mobile devices. All Address Book features can be accessible from AddressBook static class.

Before using any of the plugin's features, you need to import the namespace.

using VoxelBusters.EssentialKit;
using VoxelBusters.CoreLibrary;

After importing the namespace, AddressBook class is available for accessing all of the Address Book's features.

Get Contacts Access Status

Get the contacts access status to see if it's allowed to access or denied by the user. GetContactAccessStatus method returns AddressBookContactsAccessStatus to identify if the status is NotDetermined/Restricted/Denied/Authorized.

AddressBookContactsAccessStatus status = AddressBook.GetContactsAccessStatus();

Read Contacts

Fetch the contacts available for the user by calling ReadContacts method.

This method automatically handles the permission on first call. If user denies the permission, corresponding error with error code is returned in the callback.

ReadContacts take ReadContactsOptions where you can configure on the what and how to fetch. It provides the following options

  • Limit - How many contacts to fetch from the provided offset

  • Offset - Offset from which contacts need to be read

  • Constraints - If you want to fetch contacts only with name or email or phone number or any combination of those

//For implementing paging
ReadContactsOptions options = new ReadContactsOptions.Builder()
                                                .WithLimit(10)
                                                .WithOffset(0)
                                                .WithConstraints(ReadContactsConstraint.Name | ReadContactsConstraint.MustIncludeEmail) //Or ReadContactsConstraint.None to retrieve all or ReadContactsConstraint.Name to retrieve contacts which have name
                                                .Build();

//For retrieving all contacts
ReadContactsOptions options = new ReadContactsOptions.Builder()
                                                .Build();
                                                                                                .Build();

Along with options, you need to pass a callback to get the list of IAddressBookContact instances.

ReadContactsOptions options;
//...
//Build options with ReadContactsOptions.Builder()
//...
AddressBook.ReadContacts(options, OnReadContactsFinish);
private void OnReadContactsFinish(AddressBookReadContactsResult result, Error error)
{
    if (error == null)
    {
        var     contacts    = result.Contacts;
        Debug.Log("Request to read contacts finished successfully.");
        Debug.Log("Total contacts fetched: " + contacts.Length);
        Debug.Log("Next offset : " + result.NextOffset);
        for (int iter = 0; iter < contacts.Length && iter < 10; iter++)
        {
            Debug.Log(string.Format("[{0}]: {1}", iter, contacts[iter]));
            /*
                IAddressBookContact contact = contacts[iter];
                Debug.Log($"Name: {contact.Name}, Email: {contact.Email});
            */
        }
    }
    else
    {
        Debug.Log("Request to read contacts failed with error. Error: " + error);
    }
}
PreviousSetupNextTesting

Last updated 6 months ago

Was this helpful?

📒