1. In general , you may want to use WebView to open the internal link of the Web page and do not want to call the mobile browser, we can be implemented in the following two ways:
(1) Set a webviewclient for WebView and rewrite the shouldoverrideurlloading (WebView view, String url) method.
[Java] view plain copy
- Class Mywebviewclient extends Webviewclient {
- @Override
- Public Boolean shouldoverrideurlloading (WebView view, String URL) {
- //Override this method to indicate that clicking on a link in the Web page or jumping in the current webview does not jump to the browser
- View.loadurl (URL);
- return true;
- }
- }
(2) Set a webviewclient for WebView and rewrite the onpagestarted (WebView view, String URL, Bitmap favicon) method.
[Java] view plain copy
- Class Mywebviewclient extends Webviewclient {
- @Override
- Public void onpagestarted (WebView view, String URL, Bitmap favicon) {
- //TODO auto-generated method stub
- super.onpagestarted (view, URL, favicon);
- }
- }
Both of these methods are to let the parameter view (WebView) load the parameter URL to avoid the phone browser load URL, the first way is more common.
2. But in some cases we may want to open most of the links with WebView, and some of the links we want to call the mobile browser to open, my recent project has such a requirement. This is actually very simple, we just need to modify the first method above.
[Java] view plain copy
- Class Mywebviewclient extends Webviewclient {
- @Override
- Public Boolean shouldoverrideurlloading (WebView view, String URL) {
- //Override this method to indicate that clicking on a link in the Web page or jumping in the current webview does not jump to the browser
- if (Openwithwevview (URL)) {
- View.loadurl (URL);
- }else{
- Uri uri = uri.parse (URL); //url for the address you want to link to
- Intent Intent =new Intent (Intent.action_view, URI);
- StartActivity (Intent);
- }
- return true;
- }
where Openwithwevview (URL) is a way to write your own, to determine whether to use Wevview to open the link.
about using WebView or mobile browser to open connection issues