hi im đang cố gắng thêm số điện thoại vào liên hệ hiện có trên Android 2.1. Im hiện đang sử dụng:liên hệ chỉnh sửa 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);
nhưng tôi nhận được một lỗi:
java.lang.UnsupportedOperationException: Unknown uri: content://com.android.contacts/data/phones
làm thế nào tôi sẽ có thể khắc phục điều này?
nhờ sự giúp đỡ nào, ng93
Liệu mã cung cấp cho cùng một lỗi trên một thiết bị thực như giả lập? – sehugg
'Điện thoại' không được dùng cho Android 2.1 .... sử dụng' ContactsContract' –