I would like to capture the browsing history of all browsers on an Android phone in the last few (5 or 10) minutes. The code I'm using is
Calendar ci = Calendar.getInstance(); String enddate = "" + ci.get(Calendar.YEAR) + "-" + (ci.get(Calendar.MONTH) + 1) + "-" + ci.get(Calendar.DAY_OF_MONTH) + " " + ci.get(Calendar.HOUR) + ":" + ci.get(Calendar.MINUTE) + ":" + ci.get(Calendar.SECOND); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); ci = Calendar.getInstance(); ci.add(Calendar.MINUTE, -5); String startdate = "" + ci.get(Calendar.YEAR) + "-" + (ci.get(Calendar.MONTH) + 1) + "-" + ci.get(Calendar.DAY_OF_MONTH) + " " + ci.get(Calendar.HOUR) + ":" + ci.get(Calendar.MINUTE) + ":" + ci.get(Calendar.SECOND); long startdates = 0; long enddates = 0; try { Date endDate = (Date) new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .parse(enddate); Date startDate = (Date) new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .parse(startdate); System.out.println("End date=" + endDate.getTime()); startdates = startDate.getTime(); enddates = endDate.getTime(); } catch (ParseException e) { e.printStackTrace(); } String[] proj = new String[] { Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL, Browser.BookmarkColumns.DATE }; Uri uriCustom = Uri .parse("content://com.android.chrome.browser/bookmarks"); // 0 = history, 1 = bookmark String sel = Browser.BookmarkColumns.BOOKMARK + " = 0" + " AND " + Browser.BookmarkColumns.DATE + " BETWEEN ? AND ?"; Cursor mCur = getContentResolver().query(uriCustom, proj, sel, new String[] { "" + startdates, "" + enddates }, null); mCur.moveToFirst(); JSONObject obj; JSONArray jarray = new JSONArray(); String title = ""; String burl = ""; String date_time = ""; if (mCur.moveToFirst() && mCur.getCount() > 0) { while (mCur.isAfterLast() == false) { title = mCur.getString(mCur .getColumnIndex(Browser.BookmarkColumns.TITLE)); burl = mCur.getString(mCur .getColumnIndex(Browser.BookmarkColumns.URL)); date_time = mCur.getString(mCur .getColumnIndex(Browser.BookmarkColumns.DATE)); try { obj = new JSONObject(); obj.put("title", title); obj.put("url", burl); obj.put("date", date_time); jarray.put(obj); } catch (Exception e) { e.printStackTrace(); } mCur.moveToNext(); System.out.println(title); } }
I can get the entire browsing history from the Chrome browser if I change
String sel = Browser.BookmarkColumns.BOOKMARK + " = 0" +" AND " +Browser.BookmarkColumns.DATE+ " BETWEEN ? AND ?";
to
String sel = Browser.BookmarkColumns.BOOKMARK;
but I need a browsing history in the last few minutes to update the database. I am new to Android development. Any help would be greatly appreciated. Thanks in advance.
source share