getting the default and chrome browsers in android -


i have code retrieve history of default browser in android, lately added chrome browser history. have problem- chrome history. e.g. if there no chrome, default browser, if there chrome, both methods chrome history. use code-

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")));       }         // 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")));        }} 

can default browser , chrome? did try change "browser.bookmarks_uri" uri- "content://com.android.browser/bookmarks", didn't worked.

any suggestions?

i suppose you're using contentobserver. following:

//query values: static final string[] projection = new string[] { bookmarkcolumns.url, bookmarkcolumns.title, bookmarkcolumns.visits, bookmarkcolumns.date }; static final string selection = browser.bookmarkcolumns.bookmark + " = 0"; static final string sortorder = browser.bookmarkcolumns.date;   private static class browserhistoryobserver extends contentobserver {     public browserobserver(handler handler) {         super(handler);     }      @override     public void onchange(boolean selfchange) {         onchange(selfchange, null);     }      @override     public void onchange(boolean selfchange, uri uri) {         super.onchange(selfchange);          //retrieve visited urls:         final cursor cursor = getcontentresolver().query(browser.bookmarks_uri, projection, selection, null, sortorder);          cursor.movetofirst();         while ( !cursor.isafterlast() ) {             final string url = cursor.getstring(cursor.getcolumnindex(projection[0]));             final string title = cursor.getstring(cursor.getcolumnindex(projection[1]));             //visits = ... (cursor.getcolumnindex(projection[2]))             //date = ... (cursor.getcolumnindex(projection[3]))              log.d(tag, title + " : " + url + "\n");              cursor.movetonext();         }          //close cursor:         cursor.close();     } } 

and register/unregister like:

browserhistoryobserver = new browserhistoryobserver(new handler()); getcontentresolver().registercontentobserver(browser.bookmarks_uri, true, browserobserver);  ...  getcontentresolver().unregistercontentobserver(browserhistoryobserver); 

the code above, of course, works default android browser (indeed i've used browser.bookmarks_uri). if want make working google chrome, need replace browser.bookmarks_uri uri.parse("content://com.android.chrome.browser/bookmarks").

note have replace in both getcontentresolver().registercontentobserver(...) , getcontentresolver().query(...).


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -