如何更新通话记录中的条目内容?

发布于 2024-10-31 22:46:27 字数 748 浏览 1 评论 0原文

我想将 Android 呼叫日志中第一个条目的 CallLog.Calls.TYPE 字段从 MISSED 更新为 INCOMING。我读过书籍,开发人员参考过并用谷歌搜索过,并且我有理由确信我的代码是正确的。然而,当我实际调用 update() 时,结果是没有记录被更新。我的代码示例如下。

在你提问之前:
- 我拥有 WRITE_CONTACTS
的权限 - 要更新的记录(0)确实存在
- 我已经在 DroidX (Verizon) 和 Samsung Galaxy (AT&T) 上尝试过此操作 - 我已经尝试过此代码的各种其他更长的形式,但结果相同,

有人可以帮忙吗?

    ContentValues newValues = new ContentValues();
    newValues.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
    newValues.put(CallLog.Calls.DURATION, 50);
    int result = OsmoService.context.getContentResolver().update(
    ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, 0), 
    newValues,null,null);

I would like to update the CallLog.Calls.TYPE field of the first entry in the Android Call Log from MISSED to INCOMING. I have read books, the developers reference and googled this to death and am reasonably sure that my code is correct. However, when I actually make the call to update(), the result is that no record is updated. My code sample is below.

Before you ask:
- I have permissions for WRITE_CONTACTS
- The record to be updated (0) does exist
- I have tried this on both a DroidX (Verizon) and a Samsung Galaxy (AT&T)
- I have tried various other, longer forms of this code with same result

Can someone please help with this?

    ContentValues newValues = new ContentValues();
    newValues.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
    newValues.put(CallLog.Calls.DURATION, 50);
    int result = OsmoService.context.getContentResolver().update(
    ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, 0), 
    newValues,null,null);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

热风软妹 2024-11-07 22:46:27

如果您更新上面的代码并将行: 替换

ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, 0)

为此行:

Uri.parse("content://call_log/calls")

它可以工作。我不知道为什么,内容 URI 有点不正确。

例子:

ContentValues newValues = new ContentValues();
newValues.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
newValues.put(CallLog.Calls.DURATION, 50);
int result = OsmoService.context.getContentResolver().update(
    Uri.parse("content://call_log/calls"), 
    newValues,
    null,
    null);

If you update your code above and replace the line:

ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, 0)

with this line:

Uri.parse("content://call_log/calls")

It works. I don't know why, but something is not correct with the content URI.

example:

ContentValues newValues = new ContentValues();
newValues.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
newValues.put(CallLog.Calls.DURATION, 50);
int result = OsmoService.context.getContentResolver().update(
    Uri.parse("content://call_log/calls"), 
    newValues,
    null,
    null);
世界如花海般美丽 2024-11-07 22:46:27
ContentValues cv = new ContentValues();
cv.put(CallLog.Calls.NUMBER,"7070770"); // contact number

cv.put(CallLog.Calls.TYPE,1); // type

cv.put(CallLog.Calls.DURATION, 120); // duration in second


getContentResolver().insert(CallLog.CONTENT_URI, cv);
ContentValues cv = new ContentValues();
cv.put(CallLog.Calls.NUMBER,"7070770"); // contact number

cv.put(CallLog.Calls.TYPE,1); // type

cv.put(CallLog.Calls.DURATION, 120); // duration in second


getContentResolver().insert(CallLog.CONTENT_URI, cv);
家住魔仙堡 2024-11-07 22:46:27

例如 CallLog.Calls.CACHED_NAME

private void updateCachedName(int id, @NonNull String name) {

    ContentValues contentValues = new ContentValues();
    contentValues.put(CallLog.Calls.CACHED_NAME, name);

    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_CALL_LOG) == PackageManager.PERMISSION_GRANTED) {

        getContext().getContentResolver().update(CallLog.Calls.CONTENT_URI, contentValues, CallLog.Calls._ID + "=" + id, null);
    }
}

for example CallLog.Calls.CACHED_NAME

private void updateCachedName(int id, @NonNull String name) {

    ContentValues contentValues = new ContentValues();
    contentValues.put(CallLog.Calls.CACHED_NAME, name);

    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_CALL_LOG) == PackageManager.PERMISSION_GRANTED) {

        getContext().getContentResolver().update(CallLog.Calls.CONTENT_URI, contentValues, CallLog.Calls._ID + "=" + id, null);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文