【发布时间】:2021-04-17 13:33:09
【问题描述】:
如何使用 android 从光标中检索所有工作资料联系人。
请在此处使用 ENTERPRISE_CONTENT_FILTER_URI
更新光标 URI 格式我可以使用以下代码搜索工作资料中的任何联系人,但我正在寻找获取所有工作资料联系人而不是搜索行为
参考以下代码在工作资料中搜索联系人。
// 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();
}
让我知道如何从工作资料中检索所有联系人信息(姓名/电话/个人资料图片网址)。
【问题讨论】:
标签: android android-contacts android-contentresolver android-cursor