如何以编程方式插入带有显示名称和照片的通话记录条目?

发布于 2024-10-11 19:21:27 字数 608 浏览 1 评论 0原文

我能够以编程方式在 Android 通话记录中插入一个条目,其中包含号码、日期、持续时间和时间。输入但我不知道如何添加照片、标签和姓名? 我添加的条目适用于具有完全相同号码的现有联系人。我注意到摩托罗拉设备上的名称和;如果号码与现有联系人匹配,则会显示图片,但在我的 HTC Incredible 上缺少某些内容?

我做了以下事情..(不知道要尝试什么来拍摄照片)

ContentValues values = new ContentValues();
values.put(CallLog.Calls.NUMBER, number);
values.put(CallLog.Calls.CACHED_NAME, name);
values.put(CallLog.Calls.CACHED_NUMBER_LABEL, label);
values.put(CallLog.Calls.DATE, date);
values.put(CallLog.Calls.DURATION, duration);
values.put(CallLog.Calls.TYPE, myCallType);
context.getContentResolver().insert(CallLog.Calls.CONTENT_URI, values);

I am able to programmatically insert an entry into the Android call log with a number, date, duration & type BUT I cannot figure out how to also include a photo, label and name?
The entry I'm adding is for an existing Contact with the exact same number. I've noticed on a Motorola device the name & pic appears if the number matches an existing Contact but on my HTC Incredible something is missing?

I do the following.. (didn't know what to even try for the photo)

ContentValues values = new ContentValues();
values.put(CallLog.Calls.NUMBER, number);
values.put(CallLog.Calls.CACHED_NAME, name);
values.put(CallLog.Calls.CACHED_NUMBER_LABEL, label);
values.put(CallLog.Calls.DATE, date);
values.put(CallLog.Calls.DURATION, duration);
values.put(CallLog.Calls.TYPE, myCallType);
context.getContentResolver().insert(CallLog.Calls.CONTENT_URI, values);

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

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

发布评论

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

评论(2

小糖芽 2024-10-18 19:21:27

您无法将照片插入通话记录本身;这些信息存储在链接到通话记录条目的联系人中。有关如何执行此操作的更多信息,请参阅 ContactsContract.Data

至于 HTC 设备未使用现有照片更新通话记录,这可能与 HTC Sense 缓存通话记录条目的方式有关;我见过仅出现在 Sense 设备上的类似问题。

通话日志条目通常存储在联系人应用数据库的 calls 表中 (/data/data/com.android.providers.contacts/databases/contacts2.db)。由于某种原因,如果联系人数据发生变化,HTC Sense 似乎不会更新现有的通话记录条目,但其他 ROM 会这样做。

例如,如果我使用配备 Stock Sense 5.0 的 HTC EVO LTE 向我保存为“Jenny Smith”的某人拨打电话,则会在 calls 表中创建一个条目,其中包含一个 name 字段——存储 Jenny Smith 的位置。如果我将她的联系信息更新为“Jenny Jones”并向她拨打新电话,则 calls 表中将存储一个名为 Jenny Jones 的新条目,但之前的条目不会更改。实际的呼叫历史记录屏幕显示 Jenny Jones 的所有呼叫,但数据库本身具有旧名称。

我测试过的其他设备(包括 Nexus 5)在查看通话记录时会更新通话表中的先前条目。您的摩托罗拉设备的行为可能类似于 Nexus 5,根据需要刷新数据。

我不是数据库专家,但对它们有一定的了解。从数据库结构的角度来看,任何特定于联系人的信息都存储在该 calls 表中(它包含链接到同一字段的 raw_contacts_id 字段)对我来说似乎很奇怪在该数据库的 contacts 表中,其中存储了所有实际的联系信息),但这就是它的实现方式。

You cannot insert photos into the call log itself; those are stored in the Contact that is linked to the call log entry. See ContactsContract.Data for more information about how to do that.

As far as the HTC device not updating the call log with an existing photo, it could be tied to the way that HTC Sense caches call log entries; I have seen similar issues that only appear on Sense devices.

Call log entries are typically stored in the calls table in the Contacts app database (/data/data/com.android.providers.contacts/databases/contacts2.db). For some reason, it appears that HTC Sense does not update existing call log entries if contact data changes, but other ROMs do.

For example, if I use an HTC EVO LTE with stock Sense 5.0 to place a call to someone I have saved as "Jenny Smith", an entry is created in the calls table, which includes a name field -- where it stores Jenny Smith. If I update her contact information to "Jenny Jones" and place a new call to her, a new entry is stored in the calls table with the name Jenny Jones, but the previous entry is not changed. The actual Call History screen shows all of the calls as Jenny Jones, but the database itself has old name.

Other devices I have tested (including an Nexus 5) update previous entries in the calls table when the Call Log is viewed. Your Motorola device likely behaves like the Nexus 5, refreshing the data as needed.

I am not a database wizard, but have a reasonable amount of familiarity with them. From a database structure perspective, it seems odd to me that any contact-specific information is stored in that calls table (it contains a raw_contacts_id field that is linked to the same field in the contacts table of that database where all of the actual contact information is stored), but that's how it is implemented.

叫思念不要吵 2024-10-18 19:21:27

唯一合理的方法(无论如何对我有用)是将联系人直接添加到手机,然后添加指向该联系人的通话记录,之后您可以从手机中删除该联系人。唯一的问题是,如果您的应用程序在删除联系人之前被终止,那么您必须在下次应用程序启动时实施某种清理。对于本应简单的任务来说,这一切都非常混乱。

The only reasonable way of doing it (that works for me anyway) is to add a contact directly to the handset and then add your call log pointing at that contact, afterwards you can then remove the contact from the handset. The only issue with this is if your app gets killed before removing the contact so you would have to implement some sort of clean up on next app launch. It's all very messy for what should be a simple task.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文