Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Create Contact API 2.x
    primarykey
    data
    text
    <p>using the API I am trying to create a contact, using the API 2.x and not the old one. Here <a href="http://developer.android.com/guide/topics/providers/content-providers.html" rel="nofollow noreferrer">http://developer.android.com/guide/topics/providers/content-providers.html</a> it only explains the old API. I haven't found any proper tutorial, example, etc. showing how to create a contact. As far as I have figured out I have to create a raw contact, under raw contacts I found <a href="http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html" rel="nofollow noreferrer">http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html</a> from there I tried </p> <pre class="lang-java prettyprint-override"><code>ContentValues values = new ContentValues(); values.put(RawContacts.ACCOUNT_TYPE, accountType); //accountType = "xxxx" values.put(RawContacts.ACCOUNT_NAME, accountName); //accountName = "aaaa" Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values); long rawContactId = ContentUris.parseId(rawContactUri); values.clear(); values.put(Data.RAW_CONTACT_ID, rawContactId); values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); values.put(StructuredName.DISPLAY_NAME, "Mike Sullivan"); getContentResolver().insert(Data.CONTENT_URI, values); </code></pre> <p>The last line of code shows that "Data.CONTENT_URI" cannot be resolved. It looks a little bit that this line of code is for the 1.6 API, I have changed the Data.CONTENT_URI to ContactsContract.Data.CONTENT_URI. At least the code compiles and executes, but I still don't have a contact Mike Sullivan in my addressbook afterwards. I exchanged now as well the other "Data" with "ContactsContract.Data" still no changes.</p> <p>Has anyone an easy example how to create a person in the addressbook on 2.x?</p> <p>Edit: I made some progress, it looks like that I always need an account on my phone to add a contact. My phone has account type com.google and account name xxxxx@gmail.com. The emulator has nothing. I wonder to which account I have to add my contacts? Can I assume that I ALWAYS have exactly one gmail account and take this one? </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. 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