我正在制作一个小型Java应用程序,以显示用户访问过的Chrome中的哪些网址。我如何在Java中访问我的浏览器历史记录?
答案 0 :(得分:7)
创建ContentObserver
类...
static class ChromeOberver extends ContentObserver {
public ChromeOberver(Handler handler) {
super(handler);
}
@Override
public void onChange(boolean selfChange) {
onChange(selfChange, null);
}
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange);
Log.d(TAG, "onChange: " + selfChange);
Cursor cursor = context.getContentResolver()
.query(CHROME_BOOKMARKS_URI, new String() {"title", "url"},
"bookmark = 0", null, null);
// process cursor results
}
}
并注册该类以监控历史/书签更改:
private static String CHROME_BOOKMARKS_URI =
"content://com.android.chrome.browser/bookmarks";
ChromeOberver observer = new ChromeOberver();
resolver.registerContentObserver(CHROME_BOOKMARKS_URI, true, observer);
不要忘记许可:
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />