我有一個代碼可以在android中檢索默認瀏覽器的歷史記錄,最近我添加了Chrome瀏覽器歷史記錄。但是我有一個問題 - 我只有鉻歷史。例如。如果沒有chrome,我會得到默認的瀏覽器,如果有chrome,這兩種方法都只能獲得chrome的歷史記錄。 我使用此代碼 -獲取Android中的默認瀏覽器和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")));
}}
我可以得到默認瀏覽器,然後鉻?我確實嘗試將「Browser.BOOKMARKS_URI」更改爲uri-「content://com.android.browser/bookmarks」,但它沒有奏效。
有什麼建議嗎?