Android, How to retrieve redirect URL from a WebView? -
first surfed web no answer found matching case. want grab specific redirect url webview , keep webview opening it. case instagram redirect url after user authorized app. how it? here code:
webview = (webview) findviewbyid(r.id.webview1); webview.getsettings().setjavascriptenabled(true); webview.getsettings().setloadwithoverviewmode(true); webview.getsettings().setusewideviewport(true); webview.getsettings().setbuiltinzoomcontrols(true); webview.setwebviewclient(new webviewclient()); webview.loadurl("https://api.instagram.com/oauth/authorize/?client_id=my_client_id&redirect_uri=my_redirect_uri&response_type=code");
you have set custom webviewclient overriding shouldoverrideurlloading method webview before loading url.
mwebview.setwebviewclient(new webviewclient() { @suppresswarnings("deprecation") @override public boolean shouldoverrideurlloading(webview webview, string url) { return shouldoverrideurlloading(url); } @targetapi(build.version_codes.n) @override public boolean shouldoverrideurlloading(webview webview, webresourcerequest request) { uri uri = request.geturl(); return shouldoverrideurlloading(uri.tostring()); } private boolean shouldoverrideurlloading(final string url) { log.i(tag, "shouldoverrideurlloading() url : " + url); // here put code return true; // returning true means application wants leave current webview , handle url itself, otherwise return false. } }); mwebview.loadurl("your url"); checkout example code handling redirect urls , open pdf without download, in webview. https://gist.github.com/ashishdas09/014a408f9f37504eb2608d98abf49500
Comments
Post a Comment