Tooth uncle tutorial is easy to understand

main.js

"ui";
/* * @version: 1.0 * @date: 2021-10-18 23:16:26 * @lasteditTime: 2021-10-19 01:07:01 * @lasteditors: * @filepath: \ webView call autojs\main.js */

importClass(android.webkit.WebView);
importClass(android.webkit.WebChromeClient);
importClass(android.webkit.WebResourceResponse);
importClass(android.webkit.WebViewClient);
importClass("com.stardust.autojs.core.web.InjectableWebClient");
/ * -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * /
let sScriptEngine = engines.myEngine();
let scriptableContext = sScriptEngine.context;
let scriptableScriptable = sScriptEngine.scriptable;

let injectableWebClient = new InjectableWebClient(scriptableContext, scriptableScriptable);
log(injectableWebClient);
/ * -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * /
ui.layout(
  <linear w="*" h="*">
    <webview id="webview" h="*" w="*" />
  </linear>
);

let webview = ui.webview;

var webcc = new JavaAdapter(WebChromeClient, {
  onConsoleMessage: function (consoleMessage) {
    toastLog(consoleMessage.message());
  },
  onReceivedTitle: function (view, title) {
    if(title ! =null) {
      toastLog(title);
    } else {
      toastLog("title is null"); }}}); webview.setWebChromeClient(webcc); webview.setWebViewClient(injectableWebClient); htmlFilePath = files.path("./webView.html");
webview.loadUrl("file://" + htmlFilePath);
ui.post(function () {
  injectableWebClient.inject('document.getElementById("dateTime").innerHTML = (new Date().toLocaleString())');
}, 2000);

Copy the code

webView.html

<! DOCTYPEhtml>
<html>
  <! -- The HTML is copied directly from the rookie tutorial except js-->
  <! --https://www.runoob.com/try/try.php?filename=trybs4_button_styles-->
  <head>
    <title>Tooth tertiary tutorial</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css" />
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
  </head>
  <body>
    <h2>Autojs injection webview</h2>
    <h2>Tooth uncle tutorial is easy to understand</h2>
    <div class="container-fluid">
      <div id="dateTime"></div>
    </div>
  </body>
</html>

Copy the code

Quotes.

Ideas are the most important, other Baidu, Bing, StackOverflow, Github, Android docs, AutoJS docs, and last but not least, ask in the group

The statement

This tutorial is intended for learning purposes only and is not intended for any other use