嗨即時嘗試將電話號碼添加到Android 2.1上的現有聯繫人。即時通訊目前使用:android編輯聯繫人
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);
,但我得到一個錯誤:
java.lang.UnsupportedOperationException: Unknown uri: content://com.android.contacts/data/phones
我如何將能夠解決這一問題?
感謝您的幫助, ng93
是否代碼在真實設備上給出與仿真器相同的錯誤 – sehugg 2010-09-13 15:40:27
'Phone'已棄用於Android 2.1 ....使用'ContactsContract' – 2010-09-20 05:48:14