If you want to request the STARRED
column from the cursor, you should include it in the projection
.
favourite contact fr0m contact db
-
11-10-2022 - |
Domanda
I want to retrieve all contact then put them in different arraylist based on whether it is starred or not. I am trying to retreive all contact and do the display them separately on the basis of whether they are starred or not
contactId=8333;
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.PHONETIC_NAME };
String selection = ContactsContract.Contacts._ID + " = ?";
Cursor cur= mContext.getContentResolver().query(uri, projection, selection,
new String[] {contactId}, null);
if (cur != null && cur.moveToFirst() && cur.getCount() > 0) {
int idIndex = cur.getColumnIndex(ContactsContract.Contacts._ID);
int displayNameIndex = cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
int phoneticNameIndex = cur.getColumnIndexOrThrow(ContactsContract.Contacts.PHONETIC_NAME);
do {
String id = cur.getString(idIndex);
String name = cur.getString(displayNameIndex);
String star=cur.getString(cur.getColumnIndex(ContactsContract.Data.STARRED));
String value=cur.getString(cur.getColumnIndex(ContactsContract.Contacts.STARRED));
} while (cur.moveToNext());
}
The variable star is always null and on retrieving variable value it throws exception.
Can someone tell me how to know whetheer contact is starred or not after retrieving all the contact data?
Soluzione
Altri suggerimenti
I will go with Smutje answer, you need to add STARRED to projection, unless we wrongly understood your problem.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow