is Contact Starred - Android Account

Android examples for Account:Contact

Description

is Contact Starred

Demo Code


import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.provider.ContactsContract;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;

public class Main{
    public static boolean isContactStarred(Context context, long id) {
        int isStarred;
        Cursor cursor = context.getContentResolver().query(
                ContentUris.withAppendedId(
                        ContactsContract.Contacts.CONTENT_URI, id),
                new String[] { ContactsContract.Contacts.STARRED }, null,
                null, null);//ww  w.  jav a  2s. c  om

        if (cursor != null) {
            try {
                if (cursor.getCount() > 0) {
                    cursor.moveToFirst();
                    isStarred = Integer.valueOf(cursor.getInt(0));
                    Log.d(EmailPopup.LOG_TAG, "Is contact starred: " + id
                            + "=" + isStarred);
                } else {
                    Log.v(EmailPopup.LOG_TAG, "Count = 0");
                    isStarred = -1;
                }
            } finally {
                cursor.close();
            }
        } else {
            Log.v(EmailPopup.LOG_TAG, "Cursor is null");
            isStarred = -1;
        }

        if (isStarred == 1) {
            return true;
        } else {
            return false;
        }
    }
}

Related Tutorials