gpt4 book ai didi

java - 使用 ContentResolver 更新联系人组时更新不起作用

转载 作者:行者123 更新时间:2023-11-29 22:34:32 26 4
gpt4 key购买 nike

我有这个更新代码:

public Boolean update() {
try {
data.put(ContactsContract.Groups.SHOULD_SYNC, true);

ContentResolver cr = ctx.getContentResolver();
Uri uri = ContentUris.withAppendedId(ContactsContract.Groups.CONTENT_URI, Long.parseLong(getId()));
int mid = cr.update(uri, data,_ID+"="+getId(), null);

// notify registered observers that a row was updated
ctx.getContentResolver().notifyChange(
ContactsContract.Groups.CONTENT_URI, null);

if (-1 == mid)
return false;

return true;
} catch (Exception e) {
Log.v(TAG(), e.getMessage(), e);
return false;
}
}

我在 data 中有值,我仔细检查过,但出于某种原因,这些值被推出了。我还运行了 cur.requery(); 并且我有

<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>

编辑 1有一件事要提,我需要使用:

data.put(ContactsContract.Groups.SHOULD_SYNC, 1);

因为 true 值不被接受,尽管当您检查 ContentValues 时会返回该值。

最佳答案

我刚刚做了一些类似的工作。而不是

int mid = cr.update(uri, data,_ID+"="+getId(), null);

使用

int mid = cr.update(uri, data,null, null)

您的 uri 已经嵌入了 ID 信息。

关于java - 使用 ContentResolver 更新联系人组时更新不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2390678/

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