gpt4 book ai didi

android - 我无法更新联系人的备注部分

转载 作者:行者123 更新时间:2023-11-30 04:19:48 25 4
gpt4 key购买 nike

我正在尝试更改联系人的备注部分,我得到了他们的电话号码 (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();
}
}

最佳答案

在您从 phonelookup 获得联系人 ID (id) 之后.. 下面的内容可以使用

           ContentResolver cr = this.getContentResolver();
ContentValues values = new ContentValues();

values.clear();
String noteWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] noteWhereParams = new String[]{id,ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE};
values.put(CommonDataKinds.Note.NOTE, "NEW NOTE HERE!!!!");

cr.update(ContactsContract.Data.CONTENT_URI, values, noteWhere, noteWhereParams);

Cursor noteCur = cr.query(ContactsContract.Data.CONTENT_URI, null, noteWhere, noteWhereParams, null);
if (noteCur.moveToFirst()) {
String note = noteCur.getString(noteCur.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
Log.d(LOGTAG, "notes : " + note);
}
noteCur.close();

关于android - 我无法更新联系人的备注部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9449629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com