我有一个代码可以检索 android 中默认浏览器的历史记录,最近我添加了 chrome 浏览器历史记录。但我有一个问题 - 我只得到 chrome 历史记录。例如,如果没有 chrome,我会得到默认浏览器,如果有 chrome,这两种方法都会获取只有 chrome 的历史记录。我使用这个代码 -
String[] mProjection = {
Browser.BookmarkColumns.BOOKMARK,
BookmarkColumns.CREATED, BookmarkColumns.DATE,
BookmarkColumns.TITLE, BookmarkColumns.URL,
BookmarkColumns.VISITS,
BookmarkColumns._ID };
String mSelectionClause = "DATE > ? ";
String[] selectionArgs = {getEpochDate("DefaultBrowser")}; //"1332115200-000"
String mSortOrder = "DATE";
Cursor cr = getContentResolver().query(Browser.BOOKMARKS_URI, mProjection, mSelectionClause, selectionArgs, mSortOrder);
cr.moveToFirst();
if (cr.moveToFirst() && cr.getCount() > 0) {
while (cr.isLast() == false) {
try {
if (cr.getString(cr.getColumnIndex("BOOKMARK")).equals("0")) {
Log.d("getHistory", cr.getString(cr.getColumnIndex("TITLE")));
mc.writeDataToDB("URL", mc.ConvertFromEpoch(cr.getString(cr.getColumnIndex("DATE"))), cr.getString(cr.getColumnIndex("URL")), cr.getString(cr.getColumnIndex("TITLE")),"");
}
} catch (Exception e) {
e.printStackTrace();
}
cr.moveToNext();
}
mc.insertPref("HistoryDate", cr.getString(cr.getColumnIndex("DATE")));
}
// get google chrome history
String[] selectionArgsChrome = {getEpochDate("ChromeBrowser")};
Uri uriCustom = Uri.parse("content://com.android.chrome.browser/bookmarks");
if (getContentResolver().query(uriCustom, mProjection, mSelectionClause, selectionArgsChrome, mSortOrder) !=null){
Cursor mCur = getContentResolver().query(uriCustom, mProjection, mSelectionClause, selectionArgsChrome, mSortOrder);
mCur.moveToFirst();
String title = "";
String url = "";
String DATE = "";
if (mCur.moveToFirst() && mCur.getCount() > 0) {
boolean cont = true;
while (mCur.isAfterLast() == false && cont) {
title = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.TITLE));
url = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.URL));
DATE = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.DATE));
mc.writeDataToDB("URL", mc.ConvertFromEpoch(DATE), url, title,"");
mCur.moveToNext();
}
mc.insertPref("ChromeHistoryDate", cr.getString(cr.getColumnIndex("DATE")));
}}
我可以先获得默认浏览器,然后再获得 chrome 吗?我确实尝试将“Browser.BOOKMARKS_URI”更改为 uri-“content://com.android.browser/bookmarks”,但没有成功。
有什么建议么?