N
N
nabokovsafran2014-08-24 02:15:02
Android
nabokovsafran, 2014-08-24 02:15:02

webview. Android. How to pass the address bar back to the application?

Hello.
An Intent is created that launches the application authorization page in a contact using a WebView. How can I make this WebView launch an Activity after authorization, passing the address bar to it? Needed to get an access_token.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mintormo, 2014-08-24
@nabokovsafran

Register a special handler that runs after the page has finished loading:

...
webview.setWebViewClient(new WebViewClient() {
     public void onPageFinished (WebView view, String url) {
          if (url.startwith(redirect_url)) {
              Intent n = new Intent(....);
              n.putString("url", url);
              startActivity(n);
          }
     }
});
...

The String url parameter is the address you need. It will contain an access_token. But since redirects are possible immediately after authorization, you need to check the address so that it starts with redirect_url and then take it. redirect_url is the URL of the page that was specified in the initial authorization request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question