本文介绍了用于监听联系人更改的ContentObserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不明白为什么内容观察者会收听与联系信息无关的更改.

I really don't understand why content observer listens the changes which is not related with the contact info.

我只是注册到我想听的更改的URI:

I simply registered to the URI which I wanna listen the changes:

getContentResolver().registerContentObserver(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, true, contactsObserver);

但是在呼叫某人或发短信给某人后,它会触发并调用ContentObserver中的onChange方法.因此,尽管我不需要这样做,但我需要将所有联系人列表与我的应用程序重新同步.

But after calling someone or texting to someone, it triggers and calls onChange method in ContentObserver. So I need to re-sync all the contact list with my application although I don't need to do.

只有我感兴趣的领域:

  • ContactsContract.CommonDataKinds.Phone.CONTACT_ID
  • ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME
  • ContactsContract.CommonDataKinds.Phone.NUMBER

我应该实施哪种更改来侦听此数据库项目的更改?

What kind of changes should I implement to listen the changes for this DB items?

推荐答案

联系人"数据库​​的字段为ContactsContract.Contacts.TIMES_CONTACTED每次您与联系人列表中的某人联系时,此字段都会更新.

The Contacts database has a field ContactsContract.Contacts.TIMES_CONTACTEDThis field is updated every time you contact someone in your contact list.

甚至可以使用自己的应用程序来更新此字段,这意味着,如果您使用更新该字段的应用程序与任何联系人联系,则会调用您的onChange()方法.

It is even possible to update this field using your own app, which means, if you contact any contact using an app that updates this field, your onChange() method will be called.

这篇关于用于监听联系人更改的ContentObserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 15:23