YYPOST群发软件 发表于 2025-6-27 09:38:31

AWIROK软件H5调用app和保存配置

<span style="font-family: &quot;Microsoft Yahei&quot;, Hei, Tahoma, SimHei, sans-serif; font-size: 16px; font-weight: 700;">AWIROK软件H5调用app和保存配置</span><p></p><div><span style="font-family: &quot;Microsoft Yahei&quot;, Hei, Tahoma, SimHei, sans-serif; font-size: 16px; font-weight: 700;"><br></span></div><div><span style="font-size: 18px; color: rgb(255, 102, 0); font-weight: 700; padding-right: 10px; padding-left: 5px; font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial;">AWIROK软件H5调用app和保存配置</span><div><p id="ufd425e35" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><ignore_js_op></ignore_js_op></p><p style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px;"></p><ignore_js_op style="font-family: &quot;Microsoft YaHei&quot;, Tahoma, Helvetica, SimSun, sans-serif;"><ignore_js_op>&nbsp;</ignore_js_op>&nbsp;</ignore_js_op><span style="font-family: &quot;Microsoft YaHei&quot;, Tahoma, Helvetica, SimSun, sans-serif;"></span><ignore_js_op style="font-family: &quot;Microsoft YaHei&quot;, Tahoma, Helvetica, SimSun, sans-serif;">&nbsp;<ignore_js_op></ignore_js_op></ignore_js_op><span style="font-family: &quot;Microsoft YaHei&quot;, Tahoma, Helvetica, SimSun, sans-serif;"></span><p style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px;"></p><p id="ufd425e35" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span style="font-weight: 700;"><span class="ne-text" style="color: rgb(51, 51, 51);"><br></span></span></p><p id="ufd425e35" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span style="font-weight: 700;"><span class="ne-text" style="color: rgb(51, 51, 51);">void runJs(function code)h5执行app JS<a href="http://www.fatiegongju.com/plugin.php?id=iplus_seolinks:links&amp;url=aHR0cDovL3d3dy5wb3N0YmJzLmNvbS8=" target="_blank" class="relatedlink" style="color: rgb(133, 42, 42); transition: all 0.2s ease 0s; border-bottom: 1px solid blue;">脚本</a></span></span></p><div id="YZ7Oy" data-video-src="inputs/prod/yuque/2025/44811133/mp4/1750987317704-7b69fc27-6c36-48b7-a164-2a2dc2ac5182.mp4" class="ne-video" style="font-family: &quot;Microsoft YaHei&quot;, Tahoma, Helvetica, SimSun, sans-serif;"><br></div><div id="YZ7Oy" data-video-src="inputs/prod/yuque/2025/44811133/mp4/1750987317704-7b69fc27-6c36-48b7-a164-2a2dc2ac5182.mp4" class="ne-video" style="font-family: &quot;Microsoft YaHei&quot;, Tahoma, Helvetica, SimSun, sans-serif;"><br></div><pre data-language="javascript" id="IRTGI" class="ne-codeblock language-javascript" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>window.at.runJs(function (){
   //这里写ATjs代码
   printl("你好");
   auto.home();
}.toString());</code></pre><p id="ub9d54ee3" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span style="font-weight: 700;"><span class="ne-text" style="color: rgb(51, 51, 51);">void runJsFile(String file) H5运行APP JS文件</span></span></p><pre data-language="javascript" id="k0jkQ" class="ne-codeblock language-javascript" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>window.at.runJsFile('主脚本.js');</code></pre><p id="ue3f2a672" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span style="font-weight: 700;"><span class="ne-text" style="color: rgb(51, 51, 51);">void callFunction(String funname,String arg) H5执行脚本方法</span></span></p><pre data-language="javascript" id="Y3eaS" class="ne-codeblock language-javascript" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>window.at.callFun('main',"hello");</code></pre><p id="u899235e1" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span style="font-weight: 700;"><span class="ne-text" style="color: rgb(51, 51, 51);">String getRootPath() 获取项目根目录</span></span></p><pre data-language="javascript" id="jNbBR" class="ne-codeblock language-javascript" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>window.at.getRootPath();</code></pre><p id="uebb2b0b9" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span style="font-weight: 700;"><span class="ne-text" style="color: rgb(51, 51, 51);">String getResourcesPath() 获取项目资源目录</span></span></p><pre data-language="javascript" id="IAJdI" class="ne-codeblock language-javascript" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>window.at.getResourcesPath();</code></pre><p id="u3065f05a" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span style="font-weight: 700;"><span class="ne-text" style="color: rgb(51, 51, 51);">void setConfig(String path,String arg,String value) 存储数据</span></span><span class="ne-text" style="color: rgb(51, 51, 51);"><br></span><span class="ne-text" style="color: rgb(51, 51, 51);">path:存储路径,例如/sdcard/1.txt;<br></span><span class="ne-text" style="color: rgb(51, 51, 51);">arg:参数<br></span><span class="ne-text" style="color: rgb(51, 51, 51);">value:存储值</span></p><pre data-language="javascript" id="TFmtP" class="ne-codeblock language-javascript" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>window.at.setConfig('/sdcard/1.txt','a','1');
//例如存储到资源目录
let res=window.at.getResourcesPath();
window.at.setConfig(res+'1.txt','a','1');</code></pre><p id="u88839f9a" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span style="font-weight: 700;"><span class="ne-text" style="color: rgb(51, 51, 51);">String getConfig(String path,String arg,String value) 读取数据</span></span><span class="ne-text" style="color: rgb(51, 51, 51);"><br></span><span class="ne-text" style="color: rgb(51, 51, 51);">path:存储路径,例如/sdcard/1.txt;<br></span><span class="ne-text" style="color: rgb(51, 51, 51);">arg:参数<br></span><span class="ne-text" style="color: rgb(51, 51, 51);">value:默认值,没有数据的情况下默认返回</span></p><pre data-language="javascript" id="mQZL9" class="ne-codeblock language-javascript" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>window.at.getConfig('/sdcard/1.txt','a','1');

//从资源目录取数据
let res=window.at.getResourcesPath();
window.at.getConfig(res+'1.txt','a','1');</code></pre><p id="ud7d1432d" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span style="font-weight: 700;"><span class="ne-text" style="color: rgb(51, 51, 51);">publicSet(String key,String value) 公共变量传参</span></span></p><pre data-language="javascript" id="NwUwK" class="ne-codeblock language-javascript" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>window.at.publicSet('a','1');

//对应aiwork取值就是
publicData.get('a')</code></pre><p id="u0858d3a7" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span style="font-weight: 700;"><span class="ne-text" style="color: rgb(51, 51, 51);">publicGet(String key) 公共变量读参</span></span></p><pre data-language="javascript" id="VvXee" class="ne-codeblock language-javascript" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>window.at.publicGet('a');


//对应aiwork写值就是
publicData.set('a','1')</code></pre><p id="ube96bf36" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span class="ne-text" style="color: rgb(51, 51, 51);">完整HTML案例</span></p><pre data-language="html" id="JlMax" class="ne-codeblock language-html" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;方式一&lt;/title&gt;
    &lt;script language="JavaScript"&gt;
      function test() {

         window.at.runJs(function (){
                //这里写js代码
                printl("你好");
         }.toString());

         /*
         window.at.close();
         window.at.runJsFile('主脚本.js');
          */
      }
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;input type="Button" width="300" value="启动脚本"onClick="test()"/&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre><h1 id="h1--strong-app-h5-strong-" style="margin-top: 26px; margin-bottom: 10px; font-size: 28px; font-family: &quot;Microsoft YaHei&quot;, Tahoma, Helvetica, SimSun, sans-serif; line-height: 36px;"><span class="ne-text" style="color: rgb(51, 51, 51);">APP调用H5</span><span class="ne-text" style="color: rgb(51, 51, 51);">:</span></h1><p id="u607ac54c" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span style="font-weight: 700;"><span class="ne-text" style="color: rgb(51, 51, 51);">首先获取web控件,例如web控件的自定义ID是web</span></span></p><pre data-language="javascript" id="ISfmJ" class="ne-codeblock language-javascript" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>//初始化一个activity页面
var ac = new activity();
ac.loadXML(`
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
&gt;

    &lt;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" /&gt;

    &lt;WebView
      android:id="@+id/web"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1" /&gt;

&lt;/LinearLayout&gt;
`)

sleep.millisecond(毫秒 = 400);

var web1 = ac.findWebViewById('web');</code></pre><p id="u00f97376" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span style="font-weight: 700;"><span class="ne-text" style="color: rgb(51, 51, 51);">加载网址</span></span><span class="ne-text" style="color: rgb(51, 51, 51);">loadUrl(url)</span></p><pre data-language="javascript" id="i3YaV" class="ne-codeblock language-javascript" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>web1.url('/代码/h5.html');</code></pre><p id="u8fc53137" class="ne-p" style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px; min-height: 24px;"><span class="ne-text" style="color: rgb(51, 51, 51);">执行h5的js方法,注意代码事字符串<br></span><span class="ne-text" style="color: rgb(51, 51, 51);">String runWebJs(String jscode)<br></span><span class="ne-text" style="color: rgb(51, 51, 51);">返回值:类似js中eval执行js代码的返回值,一般是返回最后一个变量的值</span></p><pre data-language="plain" id="vrl1A" class="ne-codeblock language-plain" style="border: 1px solid rgb(232, 232, 232); border-radius: 2px; background: rgb(249, 249, 249); padding: 16px; font-size: 13px; color: rgb(89, 89, 89);"><code>复制//让浏览器运行js代码
web1.runWebJs(`alert("123")`);</code></pre><div style="font-family: &quot;Microsoft YaHei&quot;, 微软雅黑, 宋体, Tahoma, Helvetica, SimSun, sans-serif;"><code><br></code></div><p style="font-family: &quot;Lucida Grande&quot;, Geneva, Verdana, Arial; font-size: 12px;"></p></div></div>
页: [1]
查看完整版本: AWIROK软件H5调用app和保存配置