Stack Exchange
Get Favorites Contacts list always null?
I tried to get all contacts same Favorites Contacts List on Samsung galaxy S4. I am using code below:
public void getFavoritesContactsList(ContentResolver cr) {


        Uri queryUri = ContactsContract.Contacts.CONTENT_URI;

        String[] projection = new String[] {
                ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME,
                ContactsContract.Contacts.STARRED};

        String selection =ContactsContract.Contacts.STARRED + "="+"1";

        Cursor cursor = managedQuery(queryUri, projection, selection, null, null);

        while (cursor.moveToNext()) {
            String contactID = cursor.getString(cursor
                    .getColumnIndex(ContactsContract.Contacts._ID));

            Intent intent = new Intent(Intent.ACTION_VIEW);
            Uri uri = Uri.withAppendedPath(
                ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
            intent.setData(uri);
            String intentUriString = intent.toUri(0);

            String title = (cursor.getString(
                cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));

            name1.add(title);
            _idd.add(contactID);
        }

        cursor.close();
     }

But result always null.

Your code is perfect. Please check do you really have any favorite contact and also check your manifest that you have entered READ_CONTACT permission

@Praveen: Thanks, I have checked Favorites group in Android device and It's have a lot of favorite contact, and I have "android.permission.READ_CONTACTS" in manifest too. I dont know what happens?

I just ran your code on my SAMSUNG S duos.. It is perfect.. Showed all my favorite contacts... How are you displaying your favorite contacts..

I using listview to display favorite contacts. Dont worry about display, because I just using that listview to display all contacts before.
I tried to debug and count result, but always null!

I used this line  Toast.makeText(getApplicationContext(), title, Toast.LENGTH_SHORT).show();    inside while loop.. It showed all favorite contacts

public Map getFavoriteContacts(){

    Map contactMap = new HashMap();

    Uri queryUri = ContactsContract.Contacts.CONTENT_URI;

    String[] projection = new String[] {
            ContactsContract.Contacts._ID,
            ContactsContract.Contacts.DISPLAY_NAME,
            ContactsContract.Contacts.STARRED};

    String selection =ContactsContract.Contacts.STARRED + "='1'";

    Cursor cursor = managedQuery(queryUri, projection, selection, null, null);

    while (cursor.moveToNext()) {
        String contactID = cursor.getString(cursor
                .getColumnIndex(ContactsContract.Contacts._ID));

        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.withAppendedPath(
            ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
        intent.setData(uri);
        String intentUriString = intent.toUri(0);

        String title = (cursor.getString(
            cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));

        contactMap.put(title,intentUriString);
    }

    cursor.close();
    return contactMap;
}

