如何使用android平台获取所有工作资料联系人

问题描述

如何使用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);
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();
}

告诉我如何从工作资料中检索所有联系人信息(姓名/电话/个人资料图片网址)。

解决方法

API 的设计不支持这一点。

考虑一个拥有数千名员工的组织,使用的是旧的廉价电话。 这可能会阻塞小手机的内存。

因此,API 允许组织基于搜索实现对某些员工的获取。

要获取整个列表,您可以暴力破解该 API,搜索所有可能的名称前缀,并存储所有结果。如果您的应用在拥有众多员工的组织上运行,请确保您的应用不会崩溃。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...