public class ContactsManager
- Object
- 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
idString- 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
idString- of the Contact
includesFullNameboolean- if true try to fetch the full name of the Contact(not just display name)
includesPictureboolean- if true try to fetch the Contact Picture if exists
includesNumbersboolean- if true try to fetch all Contact numbers
includesEmailboolean- if ture try to fetch all Contact Emails
includeAddressboolean- 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
firstNameString- the Contact firstName
familyNameString- the Contact familyName
workPhoneString- the Contact work phone or null
homePhoneString- the Contact home phone or null
mobilePhoneString- the Contact mobile phone or null
emailString- 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
idString- 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
withNumbersboolean- if true returns only contacts that has a number
includesFullNameboolean- if true try to fetch the full name of the Contact(not just display name)
includesPictureboolean- if true try to fetch the Contact Picture if exists
includesNumbersboolean- if true try to fetch all Contact numbers
includesEmailboolean- if true try to fetch all Contact Emails
includeAddressboolean- 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
withNumbersboolean- if true returns only contacts that has a number
includesFullNameboolean- if true try to fetch the full name of the Contact(not just display name)
includesPictureboolean- if true try to fetch the Contact Picture if exists
includesNumbersboolean- if true try to fetch all Contact numbers
includesEmailboolean- if true try to fetch all Contact Emails
includeAddressboolean- 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