我如何观察联系人的任何变化

发布于 2024-08-07 05:44:24 字数 331 浏览 6 评论 0原文

在 Android 中,我如何观察对联系人所做的任何更改? 我知道我需要注册内容观察员?但是传递给 registerContentObserver 函数的 URI 应该是什么?

这是我尝试过的:

registerContentObserver( ContentUris.withAppendedId(People.CONTENT_URI, personId), true, myContactsObserver);

但是当我更改联系人的电话号码时,我没有收到通知。

感谢您的指点。

In Android, how can I observe for any changes made to a contact?
I know I need to register for a content observer? But what should be the URI for passing to the registerContentObserver function?

Here is what I tried:

registerContentObserver( ContentUris.withAppendedId(People.CONTENT_URI, personId), true, myContactsObserver);

But I don't get notified when I change the phone number of the contact.

Thank you for any pointers.

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

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

发布评论

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

评论(1

深爱成瘾 2024-08-14 05:44:24

更多信息将更容易弄清楚。

我想知道是否是因为当联系人更改时您的 Activity 不再运行。如果您通过内置联系人应用程序更改联系人,则意味着您的活动不再位于堆栈顶部,因此无法保证它仍然驻留。

您可以尝试在您明确启动和停止的服务中注册联系观察者。

More information would make it easier to figure out.

I wonder if it's because your Activity is no longer running when the contact changes. If you're changing the contact through the built-in Contacts application, that would imply that your activity is no longer at the top of the stack, so there's no guarantee that it's still resident.

You might try registering the contact observer in a service that you explicitly start and stop.

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