HarmonyOS h5加载二维码屏幕变亮

web组件里面嵌套的H5页面中有二维码,有没有办法在二维加载出来后,同时控制调整手机屏幕的亮度,使得更加亮一些呢

HarmonyOS
2024-12-24 15:26:44
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

可以在H5加载二维码时调用ArkTS方法,调整屏幕亮度,具体可参考API:

Web:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/web-in-page-app-function-invoking-V5

设置屏幕亮度:https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs-V5/faqs-arkui-132-V5

//index.ets
import { window } from '@kit.ArkUI'
import { webview } from '@kit.ArkWeb';

@Entry
@Component
struct Index{
  @State message: string = 'Hello World';
  webviewController: webview.WebviewController = new webview.WebviewController();
  @State testObj: testClass = new testClass();

  build() {
    Column() {
      Web({src:$rawfile("test.html"), controller: this.webviewController})
        // 将对象注入到web端
        .javaScriptProxy({
          object: this.testObj,
          name: "testObjName",
          methodList: ["changeBright"],
          controller: this.webviewController
        })
    }
    .height('100%')
    .width('100%')
  }
}


class testClass {
  windowStage: window.WindowStage = AppStorage.get('windowStage') as window.WindowStage;
  // 获取主窗口的方式
  mainWin: window.Window = this.windowStage.getMainWindowSync();

  constructor() {
  }

  changeBright() {
    // 修改brightness即可改变屏幕亮度
    let brightness = 1;
    this.windowStage = AppStorage.get('windowStage') as window.WindowStage;
    // 获取主窗口的方式
    this.mainWin = this.windowStage.getMainWindowSync();
    // 获取最上层窗口的方式
    window.getLastWindow(getContext(this));
    try {
      this.mainWin.setWindowBrightness(brightness, (err) => {
        if (err.code) {
          console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));
          return;
        }
        console.info('Succeeded in setting the brightness.');
      });
    } catch (exception) {
      console.error('Failed to set the brightness. Cause: ' + JSON.stringify(exception));
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.

h5:

<!DOCTYPE html>
  <html lang="en">
  <head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>基础HTML页面</title>
  <!-- 可以在这里添加CSS样式或JavaScript脚本的链接 -->
  </head>
  <body>
  <script>
  function callArkTS() {
    testObjName.changeBright();
    <!--        document.getElementById("demo").innerHTML = str;-->
      <!--        console.info('ArkTS Hello World! :' + str);-->
  }
  </script>
  <h1>欢迎来到我的网站</h1>
  <p>这是一个基础的HTML页面示例。</p>

  <div>
  <!--    <p style="width:200px;height:100px;font-size:15px" id="demo1">demo</p>-->
  <button style="width:200px;height:50px" onclick="callArkTS()">changeBright</button>
  </div>
  </br>
  <form style="height:200px">
  <label for="username1">用户名:</label>
  <input type="text" id="username1" name="username" placeholder="请输入用户名"></br>

  <label for="password1">密码:</label>
  <input type="password" id="password1" name="password" placeholder="请输入密码"></br>

  <input type="submit" value="提交">
  </form>

  <!-- 可以在这里添加更多的HTML内容 -->
  </body>
  </html>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
分享
微博
QQ
微信
回复
2024-12-24 18:17:40


相关问题
HarmonyOS 二维生成失败
401浏览 • 1回复 待解决
HarmonyOS zxing二维
619浏览 • 1回复 待解决
HarmonyOS 二维条码扫描识别
983浏览 • 1回复 待解决
HarmonyOS如何无感知扫描二维
800浏览 • 1回复 待解决
HarmonyOS 支持扫描二维吗?
823浏览 • 1回复 待解决
HarmonyOS 二维生成的demo
786浏览 • 2回复 待解决
HarmonyOS APP可以生成二维,扫安装
1163浏览 • 1回复 待解决
二维扫描三方库推荐
561浏览 • 1回复 待解决
HarmonyOS扫描二维的方案是什么?
2537浏览 • 1回复 待解决
Canvas组件实现二维中心内嵌图标
1241浏览 • 1回复 待解决
HarmonyOS 二维显示和导出base64
399浏览 • 1回复 待解决
openHarmony-Api8项目,如何生成二维
1362浏览 • 0回复 待解决