Chapter 30 Browsing the Web and WebView
Challenge: Supporting Non-HTTP Links
If you poke around within PhotoPageFragment’s WebView, you may stumble upon non-HTTP links.
For example, as of this writing, the photo detail page Flickr provides displays an Open in App button.
Pressing this button is supposed to launch the Flickr app if it is installed. If it is not installed, the
Google Play Store should launch and offer the option to install the Flickr app.
However, if you press Open in App, the WebView instead displays error text, as shown in Figure 30.4.
Figure 30.4 Open in App error
This is because you provided a WebViewClient that tells the WebView to always try to load the URI into
itself, even if the URI scheme is not supported by WebView.
To fix the error, you want non-HTTP URIs to be handled by the application that is the best fit for
the URI. Before a URI is loaded, check the scheme. If the scheme is not HTTP or HTTPS, issue an
Intent.ACTION_VIEW for the URI.