gpt4 book ai didi

java - 如何搜索工作资料联系人

转载 作者:行者123 更新时间:2023-11-29 02:36:15 25 4
gpt4 key购买 nike

我遇到一个问题,但无法在 Internet 上找到解决方案。我能够列出所有用户个人资料联系人,但不显示工作个人资料中的联系人。

有关工作资料的详细信息,请参阅以下链接 https://support.google.com/work/android/answer/6191949?hl=en https://support.google.com/work/android/answer/7029561?hl=en

`

private static final String[] PROJECTION =
{
Contacts._ID,
Contacts.LOOKUP_KEY,
Build.VERSION.SDK_INT
>= Build.VERSION_CODES.HONEYCOMB ?
Contacts.DISPLAY_NAME_PRIMARY :
Contacts.DISPLAY_NAME

};

private static final String SELECTION =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
Contacts.DISPLAY_NAME_PRIMARY + " LIKE ?" :
Contacts.DISPLAY_NAME + " LIKE ?";

@Override
public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
/*
* Makes search string into pattern and
* stores it in the selection array
*/
mSelectionArgs[0] = "%" + mSearchString + "%";
// Starts the query
return new CursorLoader(
getActivity(),
Contacts.CONTENT_URI,
PROJECTION,
SELECTION,
mSelectionArgs,
null
);
}
`

例如:我在普通个人资料中有一个名为“todd”的联系人,而在我的工作个人资料中有一个名为“tom”的联系人。现在在 native 消息应用程序中,在撰写期间它会同时显示 todd 和 tomm。我希望在我的实现中发生同样的事情。

我应该如何获取工作资料联系人?

最佳答案

引用下面的代码解决了我的问题

private static final String[] PROJECTION_ENTERPRISE = new String[]{
ContactsContract.Contacts._ID,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.DATA1,
ContactsContract.CommonDataKinds.Phone.MIMETYPE,
ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.CommonDataKinds.Phone.LABEL
};

@RequiresApi(api = Build.VERSION_CODES.N)
private Cursor getEnterpriseContact(String searchString, String[] cols, ContactSearchType mContactSearchType, String digits, String sortOrder) {
// Get the ContentResolver
ContentResolver cr = mContext.getContentResolver();
// Get the Cursor of all the contacts
Uri phoneUri = ContactsContract.CommonDataKinds.Phone.ENTERPRISE_CONTENT_FILTER_URI.buildUpon().appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(ContactsContract.Directory.ENTERPRISE_DEFAULT)).build();
Uri phoneUriWithSearch = Uri.withAppendedPath(phoneUri, Uri.encode(searchString));
Cursor pCursor = cr.query(phoneUriWithSearch, cols, null, null, sortOrder);
Cursor workCur = null;
if (mContactSearchType != ContactSearchType.CONTACT_WITH_PHONE_NO) {
Uri emailUri = ContactsContract.CommonDataKinds.Email.ENTERPRISE_CONTENT_FILTER_URI.buildUpon().appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(ContactsContract.Directory.ENTERPRISE_DEFAULT)).build();
Uri emailUriWithSearch = Uri.withAppendedPath(emailUri, Uri.encode(searchString));
Cursor eCursor = cr.query(emailUriWithSearch, cols, null, null, sortOrder);
workCur = new MergeCursor(new Cursor[]{pCursor, eCursor});
} else {
workCur=pCur;
}
return workCur;
}

关于java - 如何搜索工作资料联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46910258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com