views:

108

answers:

2

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!

+2  A: 

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.
Dave Webb
This helps me out a lot, thanks!
Tyler
+1  A: 

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.

GrkEngineer