Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android edit contact

hi im trying to add a phone number to an existing contact on android 2.1. Im currently using:

ContentValues values = new ContentValues();
values.put(Phone.RAW_CONTACT_ID,cursor.getColumnIndex(Phone.CONTACT_ID));
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI,null, selection, null,ContactsContract.Contacts.DISPLAY_NAME+" COLLATE LOCALIZED ASC");
if (cursor.getCount() > 0) {
    cursor.moveToPosition(oldcontactid);
    contactid = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
    values.put(Phone.RAW_CONTACT_ID,cursor.getColumnIndex(Phone.CONTACT_ID));
    if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
        Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{contactid}, null);
        while (pCur.moveToNext()) {
            values.put(Phone.NUMBER,pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
            values.put(Phone.TYPE, Phone.TYPE_MOBILE);
        }
        pCur.close();
    }
}
Uri uri = getContentResolver().insert(Phone.CONTENT_URI, values);

but i get an error:

java.lang.UnsupportedOperationException: Unknown uri: content://com.android.contacts/data/phones

how would i be able to fix this?

thanks for any help, ng93

like image 958
ng93 Avatar asked Jul 03 '10 12:07

ng93


2 Answers

http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/1/

http://developer.android.com/resources/samples/ContactManager/src/com/example/android/contactmanager/ContactAdder.html

check this both link it will help :)

like image 72
ud_an Avatar answered Oct 05 '22 07:10

ud_an


Insert into Data.CONTENT_URI instead of Phone.CONTENT_URI also insert the Data.MIMETYPE column with Phone.CONTENT_ITEM_TYPE.

like image 33
Denis Souza Avatar answered Oct 05 '22 08:10

Denis Souza