# Class ContactsManager

java.lang.Object
com.codename1.contacts.ContactsManager

public class ContactsManager extends java.lang.Object

`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);
        });
    });

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ContactsManager()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static String`
  `createContact(String firstName, String familyName, String workPhone, String homePhone, String mobilePhone, String email)`
  Create a contact to the device contacts book
  `static boolean`
  `deleteContact(String id)`
  removed a contact from the device contacts book
  `static String[]`
  `getAllContacts()`
  This method returns all contacts IDs
  `Contact[]`
  `getAllContacts(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.
  `static String[]`
  `getAllContactsWithNumbers()`
  This method returns all contacts that has a phone number
  `static Contact`
  `getContactById(String id)`
  This method returns a Contact by the contact id
  `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
  `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.
  `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!
  `boolean`
  `isGetAllContactsFast()`
  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!
  `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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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`: 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`: of the Contact

    - `includesFullName`: if true try to fetch the full name of the Contact(not just display name)

    - `includesPicture`: if true try to fetch the Contact Picture if exists

    - `includesNumbers`: if true try to fetch all Contact numbers

    - `includesEmail`: if ture try to fetch all Contact Emails

    - `includeAddress`: 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`: the Contact firstName

    - `familyName`: the Contact familyName

    - `workPhone`: the Contact work phone or null

    - `homePhone`: the Contact home phone or null

    - `mobilePhone`: the Contact mobile phone or null

    - `email`: 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`: 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`: if true returns only contacts that has a number

    - `includesFullName`: if true try to fetch the full name of the Contact(not just display name)

    - `includesPicture`: if true try to fetch the Contact Picture if exists

    - `includesNumbers`: if true try to fetch all Contact numbers

    - `includesEmail`: if true try to fetch all Contact Emails

    - `includeAddress`: 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)

    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`: if true returns only contacts that has a number

    - `includesFullName`: if true try to fetch the full name of the Contact(not just display name)

    - `includesPicture`: if true try to fetch the Contact Picture if exists

    - `includesNumbers`: if true try to fetch all Contact numbers

    - `includesEmail`: if true try to fetch all Contact Emails

    - `includeAddress`: if true try to fetch all Contact Addresses

    ###### Returns

    array of the contacts

    ###### Deprecated

    this method was incorrectly introduced use getContacts instead

  - ### isGetAllContactsFast

    public boolean isGetAllContactsFast()

    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

    ###### Deprecated

    this method was incorrectly introduced and isn't static use isAllContactsFast instead