Contacts API¶
Access and manage device contacts.
Contact Picking¶
pickContact()¶
Display a list of contacts to pick from.
Returns: Intent with contact URI
pickPhone()¶
Display a list of phone numbers to pick from.
Returns: Selected phone number string
Contact Queries¶
contactsGet()¶
Get all contacts.
Parameters:
- attributes (list, optional): Specific attributes to retrieve
Returns: List of contact JSONObject
contactsGetById()¶
Get a contact by ID.
Parameters:
- id (int): Contact ID
- attributes (list, optional): Specific attributes to retrieve
Returns: JSONObject contact data
contactsGetCount()¶
Get the total number of contacts.
Returns: Integer count
contactsGetIds()¶
Get all contact IDs.
Returns: List of contact ID integers
contactsGetAttributes()¶
Get all possible contact attributes.
Returns: List of attribute names
Content Queries¶
queryContent()¶
Query content resolver with custom parameters.
Parameters:
- uri (str): Content URI
- attributes (list, optional): Attributes to retrieve
- selection (str, optional): WHERE clause
- selectionArgs (list, optional): Selection arguments
- order (str, optional): ORDER BY clause
Returns: List of JSONObject results
queryAttributes()¶
Get attributes for a content URI.
Parameters:
- uri (str): Content URI
Returns: JSONArray of attribute names
Usage Example¶
import androidhelper
droid = androidhelper.Android()
# Pick a contact
contact_uri = droid.pickContact().result
print(f"Selected contact: {contact_uri}")
# Pick a phone number
phone = droid.pickPhone().result
print(f"Selected phone: {phone}")
# Get all contacts
contacts = droid.contactsGet().result
print(f"Total contacts: {len(contacts)}")
# Get contact by ID
contact = droid.contactsGetById(1).result
print(f"Contact: {contact}")
# Get contact attributes
attrs = droid.contactsGetAttributes().result
print(f"Available attributes: {attrs}")