Observer应该调用当且仅当ContactsContract

Observer应该调用当且仅当ContactsContract

本文介绍了ContentObserver应该调用当且仅当ContactsContract.Contacts.CONTENT_URI改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序从 android.provider.ContactsContract.Data 使用量(API> 11)和 ContactsContract.Contacts.CONTENT_URI (API< 11)来填充联系人

As my application uses content from android.provider.ContactsContract.Data (API > 11) and ContactsContract.Contacts.CONTENT_URI (API < 11) to populate Contacts.

我试图 registerContentObserver()对这些供应商。但它会调用我的 ContentObserver 即使我试图调用一个人从设备,只要我把电话。它确实引起我的 ContentObserver 这是不是对我很有用,因为没有含量的变化联系人提供

I've tried to registerContentObserver() against these provider. But it calls my ContentObserver even if I tries to Call a person from device as soon as I put the call. It does trigger my ContentObserver which is not useful for me as there's no Content Change in Contacts Provider.

根本原因:

好像 LAST_TIME_CONTACTED 或东西在 ContactsContract.Contacts.CONTENT_URI 做更改时调用实现了从设备这合法wokes由 ContentObserver

Seems like LAST_TIME_CONTACTED or something in ContactsContract.Contacts.CONTENT_URI do changes when a call has been made from device which legitimate wokes up by ContentObserver.

试过了:

private class ContactsContentObserver extends ContentObserver {
    public ContactsContentObserver() {
        super(null);
    }

    @Override
    public void onChange(boolean selfChange) {
        super.onChange(selfChange);
        Zname.getPreferences().setRefreshContact(true);
    }
}

注册 ContentObserver 的OnCreate() 活动的

ContactsContentObserver contactsContentObserver = new ContactsContentObserver();
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, false, contactsContentObserver);

registerContentObserver notifyForDescendents 审判。不过它触发了 ContentObserver

Tried with notifyForDescendents as false on registerContentObserver. Still it triggers out ContentObserver

QUES:

哪有一个寄存器 ContentObserver 这将触发当且仅当联系人信息下的CRUD(创建,更新,删除),除了 Last_Time_Contacted 或它的后代?

How can one register ContentObserver which triggers if and only if contacts information is under CRUD(Create,Update,Delete) except Last_Time_Contacted or its descendants?

推荐答案

这里的根本问题是,在注册 ContactsContract.Contacts.CONTENT_URI 不工作,你可能合理的想法。

The fundamental problem here is that registering for ContactsContract.Contacts.CONTENT_URI isn't working as you might reasonably think.

为什么你的更新,即使 notifyForDescendents 的理由是是因为乌里触发更新... ContactsContract.Contacts.CONTENT_URI 没有的正被拨打的联系人行。

The reason why you get updates even if notifyForDescendents is false is because the Uri triggering the update is... ContactsContract.Contacts.CONTENT_URI and not the contact row that is being dialled.

有问题的code在联系人应用程序可以在<一个发现href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android-apps/4.0.1_r1/com/android/providers/contacts/ContactsProvider2.java#ContactsProvider2.notifyChange%28boolean%29"相对=nofollow> grep的code 并有一个bug针对这个上的。

The offending code in the Contacts app can be found at GrepCode and there is a bug filed for this on Google Code.

因此​​,要回答你的问题,您不能注册 ContentObserver 将触发对接触特定的领域。您需要有东西在你的应用程序,这将使计算的差异,只要的onChange 火灾的轨道。

So to answer your question, you can't register a ContentObserver which will trigger for specific fields on a contact. You would need to have something in your app which will keep track of calculating the differences whenever onChange fires.

这篇关于ContentObserver应该调用当且仅当ContactsContract.Contacts.CONTENT_URI改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:56