How to insert contact information on an existing contact in Android 1.6?

I have a name, phone number and email contact. I just want to insert an additional email address and phone number for an existing contact. My questions

  • How to find a contact already exists or not?
  • How to insert values ​​for an additional or additional address?

Thanks at Advance.

+5
source share
1 answer

The white paper has new api options.

http://developer.android.com/reference/android/provider/ContactsContract.Data.html

First, find the source contact id with your criteria, for example name:

final String name = "reader";
// find "reader" contact 
String select = String.format("%s=? AND %s='%s'", 
        Data.DISPLAY_NAME, Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
String[] project = new String[] { Data.RAW_CONTACT_ID };
Cursor c = getContentResolver().query(
        Data.CONTENT_URI, project, select, new String[] { name }, null);

long rawContactId = -1;
if(c.moveToFirst()){
    rawContactId = c.getLong(c.getColumnIndex(Data.RAW_CONTACT_ID));
}
c.close();

-, rawContactId :

ContentValues values = new ContentValues();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, "1-800-GOOG-411");
values.put(Phone.TYPE, Phone.TYPE_CUSTOM);
values.put(Phone.LABEL, "free directory assistance");
Uri dataUri = getContentResolver().insert(Data.CONTENT_URI, values);

PS. :

<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>
+8

All Articles