我如何观察联系人的任何变化
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更多信息将更容易弄清楚。
我想知道是否是因为当联系人更改时您的 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.