开发者

Use URL to show new activity?

开发者 https://www.devze.com 2022-12-15 09:34 出处:网络
Inside my app, I was wondering if it was possible to make a certain URL in a WebView, when clicked, to redirect to a new activity view outside of the WebView?

Inside my app, I was wondering if it was possible to make a certain URL in a WebView, when clicked, to redirect to a new activity view outside of the WebView?

Thanks!开发者_C百科


You can monitor events in a WebView using a WebViewClient. The method you want is shouldOverrideUrlLoading(). This allows you to perform your own action when a particular URL is selected.

You set the WebViewClient of your WebView using the setWebViewClient() method.

Alternatively, you could use a specific Intent filter to "hijack" particular URLs. I think if you use this approach:

  • The user will have to confirm that they want to use your Activity for the URLs
  • It will hijacks these URLs from other applications too.


If you check out this link you will see an example of an Intent Filter being defined to launch an Activity. The website is set to call the callback URL when the user is done authenticating. This in turn gets handled by the browser and launches the Activity with the appropriate Intent Filter.

0

精彩评论

暂无评论...
验证码 换一张
取 消