WebView of Android control (return web page to APP)

Source of the problem: The webpage jumps back to the
APP to open the webpage. The webpage is placed in the server (for example, the APP opens the Baidu webpage). After opening the webpage, it needs to jump back to the APP from the webpage at a certain moment.
Implementation principle: Use URI plus Intent to implement.
URI introduction:
As far as the Android platform is concerned, URI is mainly divided into three parts: scheme, authority and path. The authority is divided into host and port. The format is as follows:
scheme://host:port/path
Take a practical example:
Write picture description here
code implementation:
web page code

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
</head>
<body>
     <a href="m://my.com/">跳转回app</a><br/>
</body>
</html>

AndrodMainfest.xml code
Add the following elements to the intent-filte of the Activity tag corresponding to the AndroidManifest manifest file:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data
      android:host="my.com" 
      android:scheme="m" />
</intent-filter>

An example screenshot is as follows:
Write picture description here
Activity code

webView.setWebViewClient(new WebViewClient(){
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
      Uri uri=Uri.parse(url);
          if(uri.getScheme().equals("m")&&uri.getHost().equals("my.com")){
              String arg0=uri.getQueryParameter("arg0");
              String arg1=uri.getQueryParameter("arg1");
          }else{
              view.loadUrl(url);
          }
      return true;
  }
});

After adding loadURL (webpage code) to the Activity code, run the APP, and click on the webpage to transfer back to the APP connection. The code will return to the shouldOverrideUrlLoading() function in the above Activity code. At this time, we can write our own The function you want to implement.
Extension:
Uri is divided into two types:
1. Without parameters uri m://my.com/
2. With parameters uri m://my.com/?arg0=0&arg1=1
Application scenarios QQ and WeChat and other SDKs can be used to implement Share web page

Guess you like

Origin blog.csdn.net/li1500742101/article/details/49004115