title: Insert contact into Android phonebook
body: <p>I am trying to insert contacts into the Android contact database. 
  I found a few tutorials (which I did not fully understand), and I've basically copied the methods from the "ContactManager" sample code from the Android SDK.</p>
  
  <p>I use this method to add a new raw contact :</p>
  
  <pre><code>public void createContact(String name, String phone, String mobile, String email) {
  ContentResolver cr = mContext.getContentResolver();
  ArrayList&lt;ContentProviderOperation&gt; ops = new ArrayList&lt;ContentProviderOperation&gt;();
  ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
          .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, mAccount.type)
          .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, mAccount.name).build());
  ops.add(ContentProviderOperation
          .newInsert(ContactsContract.Data.CONTENT_URI)
          .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
          .withValue(ContactsContract.Data.MIMETYPE,
                      ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
          .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name)
          .build());
  ops.add(ContentProviderOperation
          .newInsert(ContactsContract.Data.CONTENT_URI)
          .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
          .withValue(ContactsContract.Data.MIMETYPE,
                  ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
          .withValue(ContactsContract.CommonDataKinds.Phone.DATA10, phone)
          .withValue(ContactsContract.CommonDataKinds.Phone.TYPE,
                  ContactsContract.CommonDataKinds.Phone.TYPE_WORK).build());
  ops.add(ContentProviderOperation
          .newInsert(ContactsContract.Data.CONTENT_URI)
          .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
          .withValue(ContactsContract.Data.MIMETYPE,
                  ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
          .withValue(ContactsContract.CommonDataKinds.Phone.DATA11, mobile)
          .withValue(ContactsContract.CommonDataKinds.Phone.TYPE,
                  ContactsContract.CommonDataKinds.Phone.TYPE_WORK_MOBILE).build());
  ops.add(ContentProviderOperation
          .newInsert(ContactsContract.Groups.CONTENT_URI)
          .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
          .withValue(ContactsContract.Data.MIMETYPE, 
                  ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
          .withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
          .withValue(ContactsContract.CommonDataKinds.Email.TYPE, 
                      ContactsContract.CommonDataKinds.Email.TYPE_WORK).build());
  </code></pre>
  
  <p>As you can see I am trying to insert a name (I will later insert the separate given name and surname), office number and mobile phone number and email.</p>
  
  <p>When I run the code, I obtain this error :</p>
  
  <blockquote>
    <p>Error inserting dirty=1 mimetype=vnd.android.cursor.item/email_v2 data2=2 data1=foo@foo.com account_type=vnd.sec.contact.phone account_name=vnd.sec.contact.phone raw_contact_id=2
    android.database.sqlite.SQLiteException: table groups has no column named mimetype: , while compiling: INSERT INTO groups(dirty, mimetype, data2, data1, account_type, account_name, raw_contact_id) VALUES(?, ?, ?, ?, ?, ?, ?);</p>
  </blockquote>
  
  <p>It seems like it is trying to insert some data into the groups database although I don't really understand why.</p>
  
  <p>When I run the ContactManager sample app, it works fine, except that the contacts I add using this app do not appear in the Android phonebook, they are tagged as Invisible for some reason.</p>
  
  <p>Has anyone got a clue of what is going on ?</p>
  
  <p>Thanks !</p>