I added some raw contacts to the account I created. Does anyone know how I can access my data fields?
Here is how I added the contact:
Log.i(TAG, "Adding contact: " + username); ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); // create the contact ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI); builder.withValue(RawContacts.ACCOUNT_NAME, account.name); builder.withValue(RawContacts.ACCOUNT_TYPE, account.type); builder.withValue(RawContacts.SYNC1, username); operationList.add(builder.build()); // set display name builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); builder.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0); builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name); operationList.add(builder.build()); // set profile data builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0); builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.net.myapp.android.profile"); builder.withValue(ContactsContract.Data.DATA1, username); builder.withValue(ContactsContract.Data.DATA2, context.getString(R.string.app_name) + " Profile"); builder.withValue(ContactsContract.Data.DATA3, "View profile"); operationList.add(builder.build());
The cursor that I use to get my contacts is:
private Cursor getContactsCursor(CharSequence constraint) { Uri uri = RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(RawContacts.ACCOUNT_NAME, getString(R.string.app_name)).appendQueryParameter(RawContacts.ACCOUNT_TYPE, getString(R.string.ACCOUNT_TYPE)).build(); String[] projection = null;//new String[] { ContactsContract.Contacts.DISPLAY_NAME }; String selection = null; if (constraint != null && constraint.length() > 0) selection = ContactsContract.Contacts.DISPLAY_NAME + " LIKE '%" + constraint + "%'" ; String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; Cursor cursor = getContentResolver().query(uri, projection, selection, null , sortOrder); return cursor; }
Unfortunately, I need a Data1 field that is not one of the cursor columns. I assume the problem is related to RawContacts.CONTENT_URI Uri. What should i use instead?
source share