public class ContactsManager

  1. Object
  2. ContactsManager

ContactsManager provides access to the contacts on the device for listing, adding and deleting contacts.

The sample below demonstrates listing all the contacts within the device with their photos

Form hi = new Form("Contacts", new BoxLayout(BoxLayout.Y_AXIS));
hi.add(new InfiniteProgress());
int size = Display.getInstance().convertToPixels(5, true);
FontImage fi = FontImage.createFixed("" + FontImage.MATERIAL_PERSON, FontImage.getMaterialDesignFont(), 0xff, size, size);

Display.getInstance().scheduleBackgroundTask(() -> {
    Contact[] contacts = Display.getInstance().getAllContacts(true, true, false, true, false, false);
    Display.getInstance().callSerially(() -> {
        hi.removeAll();
        for(Contact c : contacts) {
            MultiButton mb = new MultiButton(c.getDisplayName());
            mb.setIcon(fi);
            mb.setTextLine2(c.getPrimaryPhoneNumber());
            hi.add(mb);
            mb.putClientProperty("id", c.getId());
            Display.getInstance().scheduleBackgroundTask(() -> {
                Contact cc = ContactsManager.getContactById(c.getId(), false, true, false, false, false);
                Display.getInstance().callSerially(() -> {
                    Image photo = cc.getPhoto();
                    if(photo != null) {
                        mb.setIcon(photo.fill(size, size));
                        mb.revalidate();
                    }
                });
            });
        }
        hi.getContentPane().animateLayout(150);
    });
});

Constructors

public ContactsManager()

Methods

public static String[] getAllContacts()This method returns all contacts IDs
public static String[] getAllContactsWithNumbers()This method returns all contacts that has a phone number
public static Contact getContactById(String id)This method returns a Contact by the contact id
public static Contact getContactById(String id, boolean includesFullName, boolean includesPicture, boolean includesNumbers, boolean includesEmail, boolean includeAddress)This method returns a Contact by the contact id and fills it’s data according to the given flags
public static String createContact(String firstName, String familyName, String workPhone, String homePhone, String mobilePhone, String email)Create a contact to the device contacts book
public static boolean deleteContact(String id)removed a contact from the device contacts book
public static Contact[] getContacts(boolean withNumbers, boolean includesFullName, boolean includesPicture, boolean includesNumbers, boolean includesEmail, boolean includeAddress)Notice: this method might be very slow and should be invoked on a separate thread! It might have platform specific optimizations over getAllContacts followed by looping over individual contacts but that isn’t guaranteed.
public static boolean isAllContactsFast()Indicates if the getAllContacts is platform optimized, notice that the method might still take seconds or more to run so you should still use a separate thread!
public static void refresh()Clears the contacts cache to that they will be loaded from the system the next time boolean, boolean, boolean, boolean, boolean) is called.
public Contact[] getAllContacts(boolean withNumbers, boolean includesFullName, boolean includesPicture, boolean includesNumbers, boolean includesEmail, boolean includeAddress)Deprecated Notice: this method might be very slow and should be invoked on a separate thread! It might have platform specific optimizations over getAllContacts followed by looping over individual contacts but that isn’t guaranteed.
public boolean isGetAllContactsFast()Deprecated Indicates if the getAllContacts is platform optimized, notice that the method might still take seconds or more to run so you should still use a separate thread!

Inherited methods

Constructor details

ContactsManager

public ContactsManager()

Method details

getAllContacts

public static String[] getAllContacts()
This method returns all contacts IDs

Returns

array of contacts IDs

getAllContactsWithNumbers

public static String[] getAllContactsWithNumbers()
This method returns all contacts that has a phone number

Returns

array of contacts IDs

getContactById

public static Contact getContactById(String id)
This method returns a Contact by the contact id

Parameters

id String
of the Contact

Returns

a Contact Object

getContactById

public static Contact getContactById(String id, boolean includesFullName, boolean includesPicture, boolean includesNumbers, boolean includesEmail, boolean includeAddress)
This method returns a Contact by the contact id and fills it’s data according to the given flags

Parameters

id String
of the Contact
includesFullName boolean
if true try to fetch the full name of the Contact(not just display name)
includesPicture boolean
if true try to fetch the Contact Picture if exists
includesNumbers boolean
if true try to fetch all Contact numbers
includesEmail boolean
if ture try to fetch all Contact Emails
includeAddress boolean
if ture try to fetch all Contact Addresses

Returns

a Contact Object

createContact

public static String createContact(String firstName, String familyName, String workPhone, String homePhone, String mobilePhone, String email)
Create a contact to the device contacts book

Parameters

firstName String
the Contact firstName
familyName String
the Contact familyName
workPhone String
the Contact work phone or null
homePhone String
the Contact home phone or null
mobilePhone String
the Contact mobile phone or null
email String
the Contact email or null

Returns

the contact id if creation succeeded or null if failed

deleteContact

public static boolean deleteContact(String id)
removed a contact from the device contacts book

Parameters

id String
the contact id to remove

Returns

true if deletion succeeded false otherwise

getContacts

public static Contact[] getContacts(boolean withNumbers, boolean includesFullName, boolean includesPicture, boolean includesNumbers, boolean includesEmail, boolean includeAddress)
Notice: this method might be very slow and should be invoked on a separate thread! It might have platform specific optimizations over getAllContacts followed by looping over individual contacts but that isn’t guaranteed. See isGetAllContactsFast for information.

Parameters

withNumbers boolean
if true returns only contacts that has a number
includesFullName boolean
if true try to fetch the full name of the Contact(not just display name)
includesPicture boolean
if true try to fetch the Contact Picture if exists
includesNumbers boolean
if true try to fetch all Contact numbers
includesEmail boolean
if true try to fetch all Contact Emails
includeAddress boolean
if true try to fetch all Contact Addresses

Returns

array of the contacts

isAllContactsFast

public static boolean isAllContactsFast()
Indicates if the getAllContacts is platform optimized, notice that the method might still take seconds or more to run so you should still use a separate thread!

Returns

true if getAllContacts will perform faster that just getting each contact

refresh

public static void refresh()

Clears the contacts cache to that they will be loaded from the system the next time boolean, boolean, boolean, boolean, boolean) is called.

This is only necessary on platforms that use a transactional address book, if you want to reload contact changes that have occurred outside the app. At time of writing, the only platform that does this is iOS. This method will have no effect on other platforms.

getAllContacts

public Contact[] getAllContacts(boolean withNumbers, boolean includesFullName, boolean includesPicture, boolean includesNumbers, boolean includesEmail, boolean includeAddress)
Deprecated. this method was incorrectly introduced use getContacts instead
Notice: this method might be very slow and should be invoked on a separate thread! It might have platform specific optimizations over getAllContacts followed by looping over individual contacts but that isn’t guaranteed. See isGetAllContactsFast for information.

Parameters

withNumbers boolean
if true returns only contacts that has a number
includesFullName boolean
if true try to fetch the full name of the Contact(not just display name)
includesPicture boolean
if true try to fetch the Contact Picture if exists
includesNumbers boolean
if true try to fetch all Contact numbers
includesEmail boolean
if true try to fetch all Contact Emails
includeAddress boolean
if true try to fetch all Contact Addresses

Returns

array of the contacts

isGetAllContactsFast

public boolean isGetAllContactsFast()
Deprecated. this method was incorrectly introduced and isn’t static use isAllContactsFast instead
Indicates if the getAllContacts is platform optimized, notice that the method might still take seconds or more to run so you should still use a separate thread!

Returns

true if getAllContacts will perform faster that just getting each contact