在 Android 中获取常用联系人
我正在尝试获取 Android 联系人的收藏夹列表中的所有联系人。目前,我可以获取所有组 ID,包括最喜欢的组 ID。但似乎没有联系人将该群组 ID 作为最喜欢的群组 ID。
我正在尝试获取所有组 ID 和每个组中的联系人。打印两个列表后,发现收藏夹的组id不在联系人列表中
ArrayList<String> favGroupId=new ArrayList<String>();
final String[] GROUP_PROJECTION = new String[] {
ContactsContract.Groups._ID, ContactsContract.Groups.TITLE };
Cursor cursor = getContentResolver().query(
ContactsContract.Groups.CONTENT_URI, GROUP_PROJECTION, null,
null, ContactsContract.Groups.TITLE);
while (cursor.moveToNext()) {
String id = cursor.getString(cursor
.getColumnIndex(ContactsContract.Groups._ID));
Log.v("Test",id);
String gTitle = (cursor.getString(cursor
.getColumnIndex(ContactsContract.Groups.TITLE)));
Log.v("Test",gTitle);
if (gTitle.contains("Favorite_")) {
gTitle = "Favorites";
favGroupId.add(id);
}
}
cursor.close();
I am trying to get all contacts in the favourites list of the Android contacts. Currently, I can get all the group ids including the favourite group ID. But it seems that there is no contacts that have the group ID as the favourite group ID.
I'm trying to get All groups id and contacts in each group. After printing two list, I found that the group id of favorite is not in the contact list
ArrayList<String> favGroupId=new ArrayList<String>();
final String[] GROUP_PROJECTION = new String[] {
ContactsContract.Groups._ID, ContactsContract.Groups.TITLE };
Cursor cursor = getContentResolver().query(
ContactsContract.Groups.CONTENT_URI, GROUP_PROJECTION, null,
null, ContactsContract.Groups.TITLE);
while (cursor.moveToNext()) {
String id = cursor.getString(cursor
.getColumnIndex(ContactsContract.Groups._ID));
Log.v("Test",id);
String gTitle = (cursor.getString(cursor
.getColumnIndex(ContactsContract.Groups.TITLE)));
Log.v("Test",gTitle);
if (gTitle.contains("Favorite_")) {
gTitle = "Favorites";
favGroupId.add(id);
}
}
cursor.close();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 已加星标 字段。 /developer.android.com/reference/android/provider/ContactsContract.Contacts.html">ContactsContract.Contact 类。如果您将查询更改为:
这应该返回 Android 上默认联系人应用程序的“收藏夹”选项卡中显示的所有联系人的列表。
You can use the STARRED field in the ContactsContract.Contact class. If you change your query to:
this should return a list of all contacts that appear in the Favorites tab in the default Contacts app on Android.
完整的答案,包括用于打开带有意图的联系人的intentUriString:
Complete answer, including intentUriString for opening the contact with an Intent:
使用 Kotlin 键入此内容:
Ty this with Kotlin:
这是在Java中获取收藏夹详细联系方式的完整方法
Here is the complete method to get contact details with favorite in Java