I am passing account name from a list to this method. Now i want to know which of these account names are read only in contacts table so i am iterating the cursor only once to get the contact id from raw cursor. After getting the contact_id I am using phone cursor to check whether the given id is read only or not but i am unable to do it. please have a look below
private void displayAllContactsByType(String accountName) {
Cursor rawCursor,phones = null;
rawCursor = cResolver.query(
ContactsContract.RawContacts.CONTENT_URI,
new String[]{ContactsContract.RawContacts.CONTACT_ID},
ContactsContract.RawContacts.ACCOUNT_NAME + "= ?",
new String[]{accountName},
null);
int contactIdColumn = rawCursor.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID);
int rawCursorCount = rawCursor.getCount();
Utils.Log("Account Name", accountName);
Utils.Log("Raw Size", " " + rawCursorCount);
rawCursor.moveToFirst();
Long contactId = rawCursor.getLong(contactIdColumn);
phones = cResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ? AND "+ContactsContract.RawContacts.ACCOUNT_NAME + "= ?",
new String[]{String.valueOf(contactId),accountName},
null);
phones.moveToFirst();
String isReadOnly= phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.IS_READ_ONLY));
Utils.Log("Raw Size", isReadOnly);
}