I would like to develop an android app for accessing the history of the browser with in a certain time interval by using AlaramManager, but when I access the history infomation, i'm getting the new information along with the previous history. Is there any way to to get the history of last few(5 or 10) minutes
Below is the code for accesing the browsing history
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);
//this.startManagingCursor(mCur);
mCur.moveToFirst();
String title = "";
String url = "";
String date_time="";
if (mCur.moveToFirst() && mCur.getCount() > 0) {
while (mCur.isAfterLast() == false) {
title = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.TITLE));
url = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.URL));
date_time=mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.DATE));
// Do something with title and url
System.out.println("Title="+title+"---"+url);
mCur.moveToNext();
}
}
Any help appreciated!
Append " AND " + Browser.BookmarkColumns.DATE + "BETWEEN ? AND ?"
to your sel
variable and pass new String[]{startdate, enddate}
in selectionArgs
of query method.
Modify the startdate
and enddate
as per your requirements. This method will return the data between to specific time period. We are just making sql query to get data between two particular time period. Ex :
String sel = Browser.BookmarkColumns.BOOKMARK + " = 0 " +" AND " + Browser.BookmarkColumns.DATE + "BETWEEN ? AND ?"; // 0 = history, 1 = bookmark
Cursor mCur = getContentResolver().query(uriCustom, proj, sel, new String[]{startdate, enddate}, null);