Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately, it seems that the stock "Add Contact" activity in AOSP only support the full name to be supplied (see source code for <a href="https://github.com/android/platform_packages_apps_contacts/blob/master/src/com/android/contacts/ui/EditContactActivity.java" rel="nofollow"><code>EditContactActivity.createContact()</code></a> and <a href="https://github.com/android/platform_packages_apps_contacts/blob/master/src/com/android/contacts/model/EntityModifier.java" rel="nofollow"><code>EntityModifier.parseExtras()</code></a>). </p> <p>One way to approximate what you want is to insert the contact information into the provider directly and then launch the "Edit Contact" activity as follow:</p> <pre><code>private void enlistMickey() throws RemoteException, OperationApplicationException { final ArrayList&lt;ContentProviderOperation&gt; ops = new ArrayList&lt;ContentProviderOperation&gt;(); ContentProviderOperation.Builder builder; builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI); builder.withValue(RawContacts.ACCOUNT_NAME, null); builder.withValue(RawContacts.ACCOUNT_TYPE, null); ops.add(builder.build()); builder = ContentProviderOperation.newInsert(Data.CONTENT_URI); builder.withValueBackReference(StructuredName.RAW_CONTACT_ID, 0); builder.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); builder.withValue(StructuredName.GIVEN_NAME, "Mickey"); builder.withValue(StructuredName.FAMILY_NAME, "Mouse"); ops.add(builder.build()); builder = ContentProviderOperation.newInsert(Data.CONTENT_URI); builder.withValueBackReference(Phone.RAW_CONTACT_ID, 0); builder.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE); builder.withValue(Phone.NUMBER, "01234567891"); ops.add(builder.build()); builder = ContentProviderOperation.newInsert(Data.CONTENT_URI); builder.withValueBackReference(Email.RAW_CONTACT_ID, 0); builder.withValue(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE); builder.withValue(Email.DATA, "mickey@disney.com"); ops.add(builder.build()); final ContentResolver cr = getContentResolver(); final ContentProviderResult[] res = cr.applyBatch(ContactsContract.AUTHORITY, ops); final Uri uri = ContactsContract.RawContacts.getContactLookupUri(cr, res[0].uri); final Intent intent = new Intent(); intent.setAction(Intent.ACTION_EDIT); intent.setData(uri); startActivityForResult(intent, REQUEST_CODE); } </code></pre> <p>One notable difference using this "insert and edit" mechanism compared to the "add" method is that the aggregation process in the provider will be more likely to prevent us from creating a new contact if an existing one with matching data already existed.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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