在Android中获得的最爱联系人联系人、最爱、Android

2023-09-12 08:59:54 作者:领悟”

我想获得在Android的联系人收藏夹列表中的所有联系人。目前,我可以得到所有的组ID,包括最喜欢的组ID。但似乎没有任何接触具有组ID的喜爱组ID。

我试图让所有组ID和联系人组。打印两列表后,我发现,最喜欢的组ID是不是在联系人列表中。

 的ArrayList<字符串> favGroupId =新的ArrayList<字符串>();
        最终的String [] GROUP_PROJECTION =新的String [] {
                ContactsContract.Groups._ID,ContactsContract.Groups.TITLE};
        光标光标= getContentResolver()查询(
        ContactsContract.Groups.CONTENT_URI,GROUP_PROJECTION,空,
                空,ContactsContract.Groups.TITLE);

        而(cursor.moveToNext()){
            字符串ID = cursor.getString(光标
                    .getColumnIndex(ContactsContract.Groups._ID));
            Log.v(测试,身份证);

            字符串gTitle =(cursor.getString(光标
                    .getColumnIndex(ContactsContract.Groups.TITLE)));

            Log.v(测试,gTitle);
            如果(gTitle.contains(Favorite_)){
                gTitle =收藏夹;
                favGroupId.add(ID);
            }
        }
        cursor.close();
 

解决方案

您可以使用STARRED在ContactsContract.Contact类。如果你改变你的查询:

 光标光标= this.managedQuery(
    ContactsContract.Contacts.CONTENT_URI,投影,中出演=?,
    新的String [] {1},NULL);
 
如何获取android手机联系人并按字母展示

这应该返回出现在Android上默认的联系人应用程序中的收藏夹选项卡中的所有联系人的列表。

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();

解决方案

You can use the STARRED field in the ContactsContract.Contact class. If you change your query to:

Cursor cursor = this.managedQuery(
    ContactsContract.Contacts.CONTENT_URI, projection, "starred=?",
    new String[] {"1"}, null);

this should return a list of all contacts that appear in the Favorites tab in the default Contacts app on Android.