[android] get Chrome browser history

 

<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />

 

String[] proj = new String[] { Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL, Browser.BookmarkColumns.DATE };
Uri uriCustom = Uri.parse("content://com.android.chrome.browser/bookmarks");
String sel = Browser.BookmarkColumns.BOOKMARK + " = 0"; // 0 = history, 1 = bookmark
Cursor mCur = getContentResolver().query(uriCustom, proj, sel, null, null);
mCur.moveToFirst();
String title = "";
String url = "";
String date = "";
Calendar cal = Calendar.getInstance();

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));
    long dateTime = Long.parseLong(date);
    cal.setTimeInMillis(dateTime);

    // TODO: Do something with title and url
    Log.w("MainActivity.java | send", "|" + title + " | " + url + "|" + cal.getTime().toString());

    mCur.moveToNext();
 }
}