public class ContactsHelper extends Object
SystemCapability.SysAppComponents#CONTACT| 构造器 | 说明 |
|---|---|
ContactsHelper(Context context) |
Creates a
ContactsHelper instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
long |
addContact(Contact contact) |
Creates a contact.
|
boolean |
deleteContact(String key) |
Deletes a specified contact.
|
boolean |
isLocalContact(long id) |
Checks whether the contact ID is in the local phone book.
|
boolean |
isMyCard(long id) |
Checks whether the contact ID is of "my card".
|
Contact |
queryContact(String key,
Holder holder,
ContactAttributes attrs) |
Queries a specified contact of specified attributes.
|
ContactsCollection |
queryContacts(Holder holder,
ContactAttributes attrs) |
Queries contacts with query conditions.
|
ContactsCollection |
queryContactsByEmail(String email,
Holder holder,
ContactAttributes attrs) |
Queries contacts by a specified email address, contact holder, and contact attributes.
|
ContactsCollection |
queryContactsByPhoneNumber(String phoneNumber,
Holder holder,
ContactAttributes attrs) |
Queries contacts by a phone number, holder, and contact attribute.
|
List<Group> |
queryGroups(Holder holder) |
Queries contact groups.
|
HoldersCollection |
queryHolders() |
Queries contact holders.
|
String |
queryKey(long id,
Holder holder) |
Obtains the query key of a contact based on a specified ID and holder.
|
Contact |
queryMyCard(ContactAttributes attrs) |
Queries information about "my card".
|
boolean |
updateContact(Contact contact,
ContactAttributes attrs) |
Updates specified attributes of a contact.
|
public ContactsHelper(Context context)
ContactsHelper instance.context - Indicates the application context.public ContactsCollection queryContactsByPhoneNumber(String phoneNumber, Holder holder, ContactAttributes attrs)
Permissions required: SystemPermission.READ_CONTACTS
and SystemPermission.WRITE_CONTACTS.
phoneNumber - Indicates the phone number. Only full match is supported, and wildcards are not supported.holder - Indicates the contact holder. If this parameter is null, the default holder is used for matching.attrs - Indicates the contact attribute. If this parameter is null,
all attributes will be used for matching.ContactsCollection object.public ContactsCollection queryContactsByEmail(String email, Holder holder, ContactAttributes attrs)
Permissions required: SystemPermission.READ_CONTACTS
and SystemPermission.WRITE_CONTACTS
email - Indicates the email address.holder - Indicates the contact holder. If this parameter is null, the default holder is used for matching.attrs - Indicates the contact attributes. If this parameter is null, all attributes are used for matching.ContactsCollection object.public HoldersCollection queryHolders()
Permissions required: SystemPermission.READ_CONTACTS and
SystemPermission.WRITE_CONTACTS
HoldersCollection object.public ContactsCollection queryContacts(Holder holder, ContactAttributes attrs)
Permissions required: SystemPermission.READ_CONTACTS
and SystemPermission.WRITE_CONTACTS
holder - Indicates the contact holder. If this parameter is null, the default holder is used for matching.attrs - Indicates the contact attributes. If this parameter is null, all attributes are used for matching.ContactsCollection object.public Contact queryMyCard(ContactAttributes attrs)
Permissions required: SystemPermission.READ_CONTACTS and
SystemPermission.WRITE_CONTACTS
attrs - Indicates the contact attributes. If this parameter is null, all attributes are used for matching.public Contact queryContact(String key, Holder holder, ContactAttributes attrs)
Permissions required: SystemPermission.READ_CONTACTS and
SystemPermission.WRITE_CONTACTS
key - Indicates the unique query key of a contact.holder - Indicates the contact holder. If this parameter is null, the default holder is used for matching.attrs - Indicates the contact attributes. If this parameter is null, all attributes are used for matching.ContactAttributespublic long addContact(Contact contact)
Permissions required: SystemPermission.READ_CONTACTS
and SystemPermission.WRITE_CONTACTS
contact - Indicates the contact information.Contact#getId()) if the creation is successful;
returns Contact#INVALID_CONTACT_ID if the creation fails.public boolean deleteContact(String key)
Permissions required: SystemPermission.READ_CONTACTS and
SystemPermission.WRITE_CONTACTS
key - Indicates the unique query key of a contact to delete.true if the contact is deleted; returns false otherwise.public boolean updateContact(Contact contact, ContactAttributes attrs)
Permissions required: SystemPermission.READ_CONTACTS
and SystemPermission.WRITE_CONTACTS
contact - Indicates the contact whose information is to update.attrs - Indicates the contact attributes to update. If this parameter is null,
all available attributes will be updated.true if the update is successful; returns false otherwise.public boolean isMyCard(long id)
id - Indicates the contact ID.true if the contact ID is of "my card"; returns false otherwise.public List<Group> queryGroups(Holder holder)
Permissions: SystemPermission.READ_CONTACTS,
SystemPermission.WRITE_CONTACTS
holder - Indicates the contact holder. If this parameter is null, the default holder is used for matching.public String queryKey(long id, Holder holder)
Permissions required: SystemPermission.READ_CONTACTS
and SystemPermission.WRITE_CONTACTS
id - Indicates the contact ID.holder - Indicates the contact holder. If this parameter is null, the default holder is used for matching.Contact.getKey()public boolean isLocalContact(long id)
Permissions required: SystemPermission.READ_CONTACTS
and SystemPermission.WRITE_CONTACTS
id - Indicates the contact ID.true if the contact ID is in the local phone book; returns false otherwise.