java - Get Redirected URL From Browser - Android -
here's problem want authorize app user. api provides me oauth 2.0 process
i have link " " contains app key , redirection link
eg. http://www.apiprovider?api-key=my_api_key&redirect=redirect_link
link when opened in browser asks users username , password , authorizes app, after successful authorization user redirected redirect_link
the redirect_link encoded key need store in variable
eg. https://www.twitter.com/some_profile?key=asc545as454ds44as
i dont want user visit redirect link, want fetch url , close browser, the page should not open.
i have used code open link in browser
intent httpintent = new intent(intent.action_view); httpintent.setdata(uri.parse("link_a")); startactivity(httpintent);
if open page in webview, app can listen url change shouldoverrideurlloading() callback.
if prefer open stock browser, can start service periodically poll latest url:
string lastdate = "0"; … string newdate = long.tostring(calendar.getinstance().gettimeinmillis()); cursor cursor = context.getcontentresolver().query( browser.bookmarks_uri, browser.history_projection, browser.bookmarkcolumns.date + " not null , " + browser.bookmarkcolumns.date + " > ?", lastdate, browser.bookmarkcolumns.date + " desc"); if (cursor.movetonext()) { string url = cursor.getstring(browser.history_projection_url_index); } cursor.close(); lastdate = newdate; // update timestamp when find url matches expected change, can switch activity , continue within context of app.
it possible close browser, may not polite, pov of end-user. imagine example has 5 open tabs important information, , destroyed!
note method can used chrome browser, different content provider: content://com.android.chrome.browser/bookmarks
Comments
Post a Comment