我正在尝试更改联系人的备注部分,我得到了他们的电话号码(receivedLocationSender),并且日志输出提供了正确的姓名和 ID,但我不知道如何让它替换联系人的“备注”部分。我目前所拥有的绝对没有任何作用。
private void displayContacts() {
ContentResolver contentResolver = getBaseContext().getContentResolver();
ContentValues contentValues = new ContentValues();
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(receivedLocationSender));
String[] projection = new String[] {PhoneLookup.DISPLAY_NAME, PhoneLookup._ID};
Cursor cursor = contentResolver.query(
uri,
projection,
null,
null,
null);
if(cursor!=null) {
while(cursor.moveToNext()){
String contactName = cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
String contactId = cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup._ID));
contentValues.clear();
String noteWhereParams = ContactsContract.CommonDataKinds.Note.NOTE;
String[] args = new String[] { String.valueOf(receivedLocation) };
contentValues.put(ContactsContract.CommonDataKinds.Note.NOTE, receivedLocation);
getContentResolver().update(ContactsContract.Data.CONTENT_URI, contentValues, contactId + "=?", args);
Log.d(LOGTAG, "contactMatch name: " + contactName);
Log.d(LOGTAG, "contactMatch id: " + contactId);
Log.d(LOGTAG, "contactNotes : " + ContactsContract.CommonDataKinds.Note.NOTE.toString());
}
cursor.close();
}
}