Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting favourites contacts in 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();
like image 614
vodkhang Avatar asked Jun 15 '11 00:06

vodkhang


People also ask

How do I get my favorite Contacts?

Open your Contacts application and touch the Groups tab at the top of the screen, then touch Favorites. Favorites lists the contacts you've added to the list, followed by a list of your most frequently called contacts.

What does favorites mean on Android phone?

Marking a contact as a favorite is easy, just tap on a contact's name, then select the "star" icon up at the top of the contact card. You'll then be able to see a combination of these favorite contacts and your frequently contacted people from the "Favorites" tab of the People app.


1 Answers

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.

like image 94
Cristian Avatar answered Sep 21 '22 12:09

Cristian