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
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 :)
Insert into Data.CONTENT_URI
instead of Phone.CONTENT_URI
also insert the Data.MIMETYPE
column with Phone.CONTENT_ITEM_TYPE
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With