index.html 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <html>
  2. <header>
  3. <script src="apkloader.js"></script>
  4. </header>
  5. <body style="background: #292929;">
  6. <div id="divTest" style="color: #fff;">557766</div>
  7. <button onclick="sayNativeHello()">回显C++和111</button>
  8. <div id="bb" style="height: 50px;"></div>
  9. <button onclick="startPicActivity()">选择图片</button>
  10. <div id="aa" style="height: 50px;"></div>
  11. <input id="txtA" value="5"></input> <input id="txtB" value="6"></input>
  12. <div style="height: 4px;"></div>
  13. <button id="btnSum" onclick="bindService()">绑定Service并计算上边两个数之和</button>
  14. <div id="cc" style="height: 50px;"></div>
  15. <button onclick="unbindService()">解绑Service</button>
  16. <div id="dd" style="height: 50px;"></div>
  17. <button onclick="startActivity()">启动Activity</button>
  18. <div id="ee" style="height: 50px;"></div>
  19. <button onclick="back()">返回</button>
  20. </body>
  21. <script>
  22. ApkLoader.setPackageName("com.example.plugina");
  23. function sayNativeHello(){
  24. ApkLoader.call("sayHello", {"name": "1111"});
  25. }
  26. function bindService(){
  27. let a = document.getElementById("txtA").value;
  28. let b = document.getElementById("txtB").value;
  29. alert(a + b);
  30. ApkLoader.call("bindService", {"a": a, "b": b});
  31. }
  32. function unbindService(){
  33. ApkLoader.call("unbindService", {"name": "1111"});
  34. }
  35. function startActivity(){
  36. ApkLoader.call("startActivity", {"name": "1111"});
  37. }
  38. function com_example_navitetest_sayNativeHelloEcho(msg){
  39. document.getElementById("divTest").innerHTML = msg.msg;
  40. }
  41. function startPicActivity(){
  42. ApkLoader.call("startPicActivity", {});
  43. }
  44. function back(){
  45. window.parent.frameUtil.hideIframe('CJJARSO')
  46. }
  47. ApkLoader.setEcho("sayNativeHelloEcho", com_example_navitetest_sayNativeHelloEcho);
  48. window.addEventListener('message', (event) => {
  49. const data = event.data
  50. if (!Array.isArray(data)) return
  51. const [code, argsJson] = data
  52. if (code === 'apkLoaderEcho' && ApkLoader && ApkLoader.echo){
  53. const args = JSON.parse(argsJson);
  54. ApkLoader.echo(...args);
  55. return;
  56. }
  57. if (code !== 'lowcode') return
  58. const args = JSON.parse(argsJson);
  59. cordova.callbackFromNative(...args);
  60. })
  61. </script>
  62. </html>