SoFunction
Updated on 2025-04-06

Android implements WebView click interception jump native

1. First set up the web view

(new MyWebViewClient());
(new MyWebViewClient());

2. Block the clicked link and jump to the corresponding page

 // Listen to all clicked links, if they block what we need, they will jump to the corresponding page.
 private class MyWebViewClient extends WebViewClient {

  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
   ("tsg","url==="+url);
 //Unlocking here   if (url != null && (https://)) {
 String intercepts required
    String str="";
    str=(("id/"),());
    str=(3,("."));
    ("tsg","id==="+str);
//    (mActivity, "njhnuj", Toast.LENGTH_SHORT).show();
 //Jump the page that needs to be redirected    Intent intent = new Intent();
    intent = new Intent(getActivity(), );
    ("goodsID",str);
    getActivity().startActivity(intent);
    return true;

   }
   return (view, url);
  }
  @Override

  public void onPageFinished(WebView view, String url) {
   ().setJavaScriptEnabled(true);
   (view, url);
  }

 }

Supplementary knowledge:Android 9.0 WebView blank page

Recently, I met an online customer. Some mobile phone 9.0 systems were used in the webview, and the pages were blank and the pages could not be loaded normally. . .

The reason is:

There is a new feature in Android 9.0 version as follows

All applications use HTTPS

This is an affirmation to Android security users. All applications on AndroidPie use HTTPS by default. Android cares about your privacy.

That is to say, starting with Android 9.0 (API level 28), plaintext support is disabled by default. Therefore, none of http urls can be loaded in the webview.

Solution:

Add android:usesCleartextTraffic="true" to the APplication tag in the file.

android:usesCleartextTraffic="true"

The above article on Android's realization of WebView click interception and jump native is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.