Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess raw contact data
    primarykey
    data
    text
    <p>I added some raw contacts to an account I created. Does anyone knows how can I access its data fields?</p> <p>This is how I added the contact:</p> <pre><code> Log.i(TAG, "Adding contact: " + username); ArrayList&lt;ContentProviderOperation&gt; operationList = new ArrayList&lt;ContentProviderOperation&gt;(); // 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()); </code></pre> <p>The cursor I use to get my contacts is:</p> <pre><code> 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 &amp;&amp; constraint.length() &gt; 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; } </code></pre> <p>Unfortunately, I need Data1 field, which is not one of the cursor columns. I guess that the problem is with RawContacts.CONTENT_URI Uri. What should I use instead?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload