java - Getting the current URL in an Android browser -


i'm searching way current url user visiting on android browser application. figured out can last visited url browser.bookmarks_uri database using following technique:

cursor cursor = context.getcontentresolver().query(browser.bookmarks_uri,         browser.history_projection, null, null,         browser.bookmarkcolumns.date + " desc"); cursor.movetonext(); string url = cursor.getstring(browser.history_projection_url_index); cursor.close(); 

the problem this, browser.bookmarks_uri db doesn't updated when user presses in order navigate previous page in browser, , query returns incorrect results.

see following example:

  1. user navigates www.google.com -> query returns "www.google.com"
  2. user navigates www.imdb.com -> query returns "www.imdb.com"
  3. user presses return www.google.com -> query returns "www.imdb.com" (!!)

does have idea how return correct url user viewing?

i think did not have gone through following approah. once try it! can access browsing history same way other contentproviders. besides browsing history can list of bookmarks.

cursor weblinkscursor = getcontentresolver().query(browser.bookmarks_uri, browser.history_projection, null, null, browser.bookmarkcolumns.date + " desc"); int row_count = weblinkscursor.getcount();  int title_column_index = weblinkscursor.getcolumnindexorthrow(browser.bookmarkcolumns.title); int url_column_index = weblinkscursor.getcolumnindexorthrow(browser.bookmarkcolumns.url);  if ((title_column_index > -1) && (url_column_index > -1) && (row_count > 0)) {     weblinkscursor.movetofirst();     while (weblinkscursor.isafterlast() == false)     {         if (weblinkscursor.getint(browser.history_projection_bookmark_index) != 1)         {             if (!weblinkscursor.isnull(url_column_index))             {                 log.i("history" , "last page browsed " + weblinkscursor.getstring(url_column_index));                 break;             }         }         weblinkscursor.movetonext();     }             } weblinkscursor.close(); 

and need permission also

com.android.browser.permission.read_history_bookmarks 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -