Reputation: 163
How to retrieve all the work profile contacts from cursor using android.
Please update cursor URI formation here using ENTERPRISE_CONTENT_FILTER_URI
I can search any contact in work profile using the below piece of code, but am looking for to get all the work profile contacts instead of search behavior
Reference the below piece of code for search contact in work profile.
// Build the URI to look up work profile contacts whose name matches. Query
// the default work profile directory which is the locally stored contacts.
Uri contentFilterUri = ContactsContract.Contacts.ENTERPRISE_CONTENT_FILTER_URI
.buildUpon()
.appendPath(nameQuery)
.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY,
String.valueOf(ContactsContract.Directory.ENTERPRISE_DEFAULT))
.build();
// Query the content provider using the generated URI.
Cursor cursor = getContentResolver().query(
contentFilterUri,
new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.LOOKUP_KEY,
ContactsContract.Contacts.DISPLAY_NAME_PRIMARY
},
null,
null,
null);
if (cursor == null) {
return;
}
// Print any results found using the work profile contacts' display name.
try {
while (cursor.moveToNext()) {
Log.i(TAG, "Work profile contact: " + cursor.getString(2));
}
} finally {
cursor.close();
}
Let me know how to retrieve all the contacts info(Name/phone/profile pic url) from work profile.
Upvotes: 0
Views: 281
Reputation: 28239
This is not supported by the API by design.
Consider an organization with thousands of employees, on an old, budget phone. That might choke the little phone's memory.
So instead the API allows organizations to implement a fetch of certain employees based on search.
To get the entire list, you can just brute force that API, searching all possible name prefixes, and storing all the results. Just make sure you don't crash your app if it runs on organizations with many employees.
Upvotes: 0