信息发布软件,b2b软件,广告发布软件

标题: 原生webview的h5如何跟aiwork交互 [打印本页]

作者: 群发软件    时间: 2025-2-19 09:29
标题: 原生webview的h5如何跟aiwork交互
原生webview的h5如何跟aiwork交互
  1. [p=30, 2, left]<!DOCTYPE html>
  2. <html lang="en">[/p][p=30, 2, left]<head>
  3. <meta charset="UTF-8">
  4. <title>合并页面</title>
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <style>
  7. body {
  8. background-color: #fff; /* 改为白色 */
  9. color: #333; /* 调整文字颜色以匹配白色背景 */
  10. font-family: Arial, sans-serif;
  11. padding: 20px;
  12. }[/p][p=30, 2, left].navbar {
  13. background-color: #f0f0f0; /* 改为浅色以与白色背景区分 */
  14. padding: 10px;
  15. display: flex;
  16. justify-content: space-around;
  17. color: #000;
  18. }[/p][p=30, 2, left].navbar a {
  19. text-decoration: none;
  20. color: inherit;
  21. font-weight: bold;
  22. }[/p][p=30, 2, left].section, .submenu {
  23. background-color: #fff; /* 改为白色 */
  24. color: #333; /* 调整文字颜色 */
  25. padding: 20px;
  26. margin-bottom: 20px;
  27. border-radius: 10px;
  28. box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  29. }[/p][p=30, 2, left].section input[type="checkbox"],
  30. .submenu input[type="checkbox"],
  31. input[type="radio"],
  32. input[type="text"],
  33. select,
  34. button {
  35. color: #333; /* 调整文字颜色 */
  36. background-color: #ddd; /* 改为浅色 */
  37. border: none;
  38. border-radius: 5px;
  39. padding: 10px;
  40. margin-right: 10px;
  41. box-sizing: border-box;
  42. }[/p][p=30, 2, left]button {
  43. background-color: #4CAF50;
  44. width: 60%;
  45. font-size: 20px;
  46. cursor: pointer;
  47. margin-top: 20px;
  48. color: #fff; /* 按钮文字颜色 */
  49. }[/p][p=30, 2, left]h1 {
  50. color: #e91e63;
  51. }
  52. </style>
  53. </head>[/p][p=30, 2, left]<body>
  54. <div class="navbar">
  55. <a href="#">首页</a>
  56. <a href="#">话术</a>
  57. <a href="#">选择平台</a>
  58. <a href="#">配置</a>
  59. <a href="#">其他</a>
  60. </div>[/p][p=30, 2, left]<h1>合并页面</h1>[/p][p=30, 2, left]<div class="section">
  61. <h2>超级延迟</h2>
  62. <input type="checkbox" id="charDelay" name="charDelay">
  63. <label for="charDelay">按打字数量延迟</label>
  64. <!-- 省略其他选项... -->
  65. </div>[/p][p=30, 2, left]<div class="submenu">
  66. <h2>招呼设置</h2>
  67. <input type="checkbox" id="fixed-greeting" name="fixed-greeting">
  68. <label for="fixed-greeting">钉定招呼语---勾选生效</label>
  69. <input type="text" placeholder="请输入招呼1">
  70. <input type="text" placeholder="请输入招呼2">
  71. <input type="text" placeholder="请输入招呼3">
  72. </div>[/p][p=30, 2, left]<!-- 省略其他部分... -->[/p][p=30, 2, left]<form>
  73. <div class="section">
  74. <h2>定时</h2>
  75. <input type="checkbox" id="enableTiming" name="enableTiming">
  76. <label for="enableTiming">开启定时</label><br>
  77. <!-- 省略其他选项... -->
  78. </div>[/p][p=30, 2, left]<button type="button">调用原生方法</button>
  79. <button type="button">执行脚本代码</button>
  80. <button type="button">执行脚本文件</button>
  81. <button type="button">传递控件值</button>
  82. </form>[/p][p=30, 2, left]<script language="JavaScript">
  83. function callHelloAI() {
  84. window.at.callFun('main', 'hello');
  85. }[/p][p=30, 2, left]function runJS() {
  86. window.at.runJs(function () {
  87. printl("你好");
  88. auto.recents();
  89. }.toString());
  90. }[/p][p=30, 2, left]function runJsFile() {
  91. window.at.runJsFile('主脚本.js');
  92. }[/p][p=30, 2, left]function sendText() {
  93. var inputValue = document.getElementById('input1').value;
  94. window.at.runJsFile('测试传值.js');
  95. }
  96. </script>[/p][p=30, 2, left]</body>[/p][p=30, 2, left]</html>[/p]
复制代码






原生webview的h5如何跟aiwork交互 b2b软件

原生webview的h5如何跟aiwork交互 b2b软件




原生activity和h5交互案例.zip


void runJs(function code)h5执行app JS脚本
window.at.runJs(function (){     //这里写ATjs代码     printl("你好");     auto.home();}.toString());
void runJsFile(String file) H5运行APP JS文件
window.at.runJsFile('主脚本.js');
void callFunction(String funname,String arg) H5执行脚本方法
window.at.callFun('main',"hello");
String getRootPath() 获取项目根目录
window.at.getRootPath();
String getResourcesPath() 获取项目资源目录
window.at.getResourcesPath();
void setConfig(String path,String arg,String value) 存储数据
path:存储路径,例如/sdcard/1.txt;
arg:参数
value:存储值
window.at.setConfig('/sdcard/1.txt','a','1');//例如存储到资源目录let res=window.at.getResourcesPath();window.at.setConfig(res+'1.txt','a','1');
String getConfig(String path,String arg,String value) 读取数据
path:存储路径,例如/sdcard/1.txt;
arg:参数
value:默认值,没有数据的情况下默认返回
window.at.getConfig('/sdcard/1.txt','a','1');//从资源目录取数据let res=window.at.getResourcesPath();window.at.getConfig(res+'1.txt','a','1');
publicSet(String key,String value) 公共变量传参
window.at.publicSet('a','1');//对应aiwork取值就是publicData.get('a')
publicGet(String key) 公共变量读参
window.at.publicGet('a');//对应aiwork写值就是publicData.set('a','1')
完整HTML案例
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>方式一</title>    <script language="JavaScript">        function test() {           window.at.runJs(function (){                //这里写js代码                printl("你好");           }.toString());           /*           window.at.close();           window.at.runJsFile('主脚本.js');          */        }    </script></head><body><input type="Button" width="300" value="启动脚本"  onClick="test()"  /></body></html>APP调用H5:
首先获取web控件,例如web控件的自定义ID是web
//初始化一个activity页面var ac = new activity();ac.loadXML(`<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    androidrientation="vertical" >    <TextView        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="H5演示"        android:textSize="18sp"        android:textStyle="bold"        android:gravity="center"        android:paddingBottom="8dp" />    <WebView        android:id="@+id/web"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1" /></LinearLayout>`)sleep.millisecond(毫秒 = 400);var web1 = ac.findWebViewById('web');
加载网址loadUrl(url)
复制web1.url('/代码/h5.html');
执行h5的js方法,注意代码事字符串
String runWebJs(String jscode)
返回值:类似js中eval执行js代码的返回值,一般是返回最后一个变量的值
//让浏览器运行js代码web1.runWebJs(`alert("123")`);








欢迎光临 信息发布软件,b2b软件,广告发布软件 (http://www.postbbs.com/) Powered by Discuz! X3.2