简体   繁体   English

即使使用其他URI也不会调用浏览器ContentObserver

[英]Browser ContentObserver not being called even using different URI's

My ContentObserver for observing the history in the browser is not being called. 我的用于在浏览器中观察历史记录的ContentObserver未被调用。 I don't understand why it isn't. 我不明白为什么不是这样。 I'm not doing anything different or bizarre, I'm following the API specs exactly, but to no avail! 我没有做任何不同或奇怪的事情,我完全遵循API规范,但无济于事! Below is my code: 下面是我的代码:

In my service: 为我服务:

public class MonitorService extends Service {
    //some global variables declared here
    private ContentObserver historyObserver, searchObserver, chromeObserver;

    public void onCreate() {
        super.onCreate();
        isRunning = false;
        this.preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

        //this.historyObserver = new HistoryObserver();
        this.historyObserver = new HistoryObserver(new Handler());
        this.searchObserver = new HistoryObserver(new Handler());
        this.chromeObserver = new HistoryObserver(new Handler());

        getApplicationContext().getContentResolver().registerContentObserver(Uri.parse("content://com.android.chrome.browser/history"), false, this.chromeObserver);
        getApplicationContext().getContentResolver().registerContentObserver(android.provider.Browser.BOOKMARKS_URI, false, this.historyObserver);
        getApplicationContext().getContentResolver().registerContentObserver(android.provider.Browser.SEARCHES_URI, false, this.searchObserver);
    }
//Other required methods in class
}//end of class

Then in my HistoryObserver Class we have: 然后在我的HistoryObserver类中,我们有:

public class HistoryObserver extends ContentObserver {

    public final String TAG = "HistoryObserver";

    public HistoryObserver(Handler handler) {
        super(handler);
        Log.d(TAG, "Creating new HistoryObserver");
    }

    public HistoryObserver() {
        super(null);
        Log.d(TAG, "Creating a new HistoryObserver without a Handler");
    }

    @Override
    public boolean deliverSelfNotifications() {
        Log.d(TAG, "delivering self notifications");
        return true;
    }

    @Override
    public void onChange(boolean selfChange) {
        super.onChange(selfChange);
        Log.d(TAG, "onChange without uri: " + selfChange);
        //onChange(selfChange, null);
    }

    public void onChange(boolean selfChange, Uri uri) {
        super.onChange(selfChange, uri);
        Log.d(TAG, "onChange: " + selfChange + "\t " + uri.toString());
    }
}

Like I said there is nothing special or unique about this implementation. 就像我说的那样,此实现没有什么特殊或独特之处。 Yet, when I go go to a new website or search for something in Chrome, the onChange method is never fired. 但是,当我转到新网站或在Chrome中搜索内容时,永远不会触发onChange方法。

I figured out the problem. 我解决了这个问题。 The /history content provider isn't an observable. / history内容提供程序不是可观察的。 The observables come through the /bookmark uri. 可观察者通过/ book uri获得。 Once I discovered that, things got working very quickly and very well. 一旦我发现了这一点,一切就会很快并且很好地进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用ContentObserver调用了两次同步适配器 - Sync Adapter called twice using ContentObserver Firebase“ addValueEventListener”即使处于脱机状态也被调用 - Firebase “addValueEventListener” being called even if offline 即使将字段设置为不使用Expose进行序列化,仍会调用Gson TypeAdapter的写入方法 - Gson TypeAdapter's write method is still called even if the field is set not to be serialized using Expose Spring问题 - 必须有偶数个URI - Spring issue - must have even number of URI's 春天。 “schemaLocation ...必须有偶数个URI” - spring. “schemaLocation … must have even number of URI's” 即使在连接上也不会调用Android Websockets onMessage() - Android Websockets onMessage() never being called even on connection 即使已调用catch块,代码仍在执行 - code is being executed even when catch block has been called 即使对象是子类,也会调用超类方法 - Superclass method being called even though object is of subclass 单元测试中未调用Hibernate的PreUpdateEventListener - Hibernate's PreUpdateEventListener not being called in unit tests JAXB ValidationEventHandler的handleEvent方法未被调用 - JAXB ValidationEventHandler's handleEvent method not being called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM