【问题标题】:How to get all the work profile contacts using android platform如何使用 android 平台获取所有工作资料联系人
【发布时间】: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


    【解决方案1】:

    API 在设计上不支持此功能。

    考虑一个拥有数千名员工的组织,使用的是一部旧的预算电话。 这可能会扼杀小手机的记忆。

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

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

    【讨论】:

    • 感谢更新marmor。但是如何使用 ENTERPRISE_CONTENT_FILTER_URI 内容 uri 以及需要使用哪个光标列来获取电话号码详细信息的工作资料联系号码。目前正在使用以下代码获取联系人姓名详细信息....Cursor cursor = getContentResolver().query( contentFilterUri, new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.LOOKUP_KEY, ContactsContract.Contacts.DISPLAY_NAME_PRIMARY },空,空,空);
    猜你喜欢
    • 1970-01-01
    • 2012-09-15
    • 2011-05-19
    • 2017-09-09
    • 1970-01-01
    • 2017-02-22
    • 2015-05-23
    • 2021-10-01
    相关资源
    最近更新 更多