about using WebView or mobile browser to open connection issues

Source: Internet
Author: User

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
  1. Class Mywebviewclient extends Webviewclient {
  2. @Override
  3. Public Boolean shouldoverrideurlloading (WebView view, String URL) {
  4. //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
  5. View.loadurl (URL);
  6. return true;
  7. }
  8. }


(2) Set a webviewclient for WebView and rewrite the onpagestarted (WebView view, String URL, Bitmap favicon) method.

[Java] view plain copy
  1. Class Mywebviewclient extends Webviewclient {
  2. @Override
  3. Public void onpagestarted (WebView view, String URL, Bitmap favicon) {
  4. //TODO auto-generated method stub
  5. super.onpagestarted (view, URL, favicon);
  6. }
  7. }


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
  1. Class Mywebviewclient extends Webviewclient {
  2. @Override
  3. Public Boolean shouldoverrideurlloading (WebView view, String URL) {
  4. //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
  5. if (Openwithwevview (URL)) {
  6. View.loadurl (URL);
  7. }else{
  8. Uri uri = uri.parse (URL); //url for the address you want to link to
  9. Intent Intent =new Intent (Intent.action_view, URI);
  10. StartActivity (Intent);
  11. }
  12. return true;
  13. }


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.