# harmony-utils之WindowUtil,窗口相关工具类

简介: WindowUtil 是 HarmonyOS 工具库 harmony-utils 中的窗口管理工具类,提供丰富 API 实现窗口方向、隐私模式、沉浸式布局、屏幕亮度、常亮、聚焦、触摸状态等控制,提升鸿蒙应用开发效率。

harmony-utils之WindowUtil,窗口相关工具类

harmony-utils 简介与说明


harmony-utils 一款功能丰富且极易上手的HarmonyOS工具库,借助众多实用工具类,致力于助力开发者迅速构建鸿蒙应用。其封装的工具涵盖了APP、设备、屏幕、授权、通知、线程间通信、弹框、吐司、生物认证、用户首选项、拍照、相册、扫码、文件、日志,异常捕获、字符、字符串、数字、集合、日期、随机、base64、加密、解密、JSON等一系列的功能和操作,能够满足各种不同的开发需求。
picker_utils 是harmony-utils拆分出来的一个子库,包含PickerUtil、PhotoHelper、ScanUtil。

下载安装
ohpm i @pura/harmony-utils
ohpm i @pura/picker_utils

  //全局初始化方法,在UIAbility的onCreate方法中初始化 AppUtil.init()
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    AppUtil.init(this.context);
  }

API方法与使用


setPreferredOrientation 设置窗口的显示方向属性
WindowUtil.setPreferredOrientation(window.Orientation.LANDSCAPE).then(() => {
  ToastUtil.showToast(`设置成功!`)
}).catch((err: BusinessError) => {
  LogUtil.error(err);
});
getPreferredOrientation 获取窗口的显示方向属性,主窗口调用
 let orientation = WindowUtil.getPreferredOrientation();
 DialogHelper.showToast(`窗口屏幕方向:${orientation}`);
setWindowPrivacyMode 设置窗口是否为隐私模式。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏
WindowUtil.setWindowPrivacyMode(true).then(() => {
  ToastUtil.showToast("您已设置隐私模式,禁止截屏、录像");
}).catch((err: BusinessError) => {
  LogUtil.error(err);
});
isPrivacyMode 窗口是否隐私模式,默认主窗口
 let isPrivacyMode = WindowUtil.isPrivacyMode();
 ToastUtil.showToast(`窗口是否隐私模式:${isPrivacyMode}`);
setWindowLayoutFullScreen 设置窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)
WindowUtil.setWindowLayoutFullScreen(true).then(() => {
  ToastUtil.showToast(`沉浸式布局已设置成功!`);
}).catch((err: BusinessError) => {
  LogUtil.error(err);
});
isLayoutFullScreen 判断窗口是否为沉浸式,默认主窗口
 let isLayoutFullScreen = WindowUtil.isLayoutFullScreen();
 ToastUtil.showToast(`窗口是否为沉浸式:${isLayoutFullScreen}`);
setWindowSystemBarProperties 设置主窗口三键导航栏、状态栏的属性
WindowUtil.setWindowSystemBarProperties({
  statusBarColor: '#F00FF0',
  statusBarContentColor: '#0FF00F',
  isStatusBarLightIcon: true,
  navigationBarColor: '#F06060',
  navigationBarContentColor: "#0606F0",
  isNavigationBarLightIcon: true
}).then(() => {
  ToastUtil.showToast("设置成功!");
}).catch((err: BusinessError) => {
  LogUtil.error(err);
});
getWindowSystemBarProperties 获取主窗口三键导航栏、状态栏的属性
   let properties = WindowUtil.getWindowSystemBarProperties();
   let jsonStr = JSON.stringify(properties, null, 2);
setImmersiveModeEnabledState 设置当前窗口是否开启沉浸式布局,该调用不会改变窗口模式和窗口大小
  WindowUtil.setImmersiveModeEnabledState(true);
getImmersiveModeEnabledState 查询当前窗口是否已经开启沉浸式布局
  let enabled = WindowUtil.getImmersiveModeEnabledState();
  ToastUtil.showToast(`是否开启沉浸式布局:${enabled}`);
setWindowGrayScale 设置窗口灰阶。该接口需要在调用loadContent()或setUIContent()使窗口加载页面内容后调用。
 WindowUtil.setWindowGrayScale(1.0);
setWindowBackgroundColor 设置窗口的背景色。Stage模型下,该接口需要在loadContent()或setUIContent()调用生效后使用
  WindowUtil.setWindowBackgroundColor('#9932CC');
  ToastUtil.showToast("设置背景色成功!");
setWindowSystemBarEnable 设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制
WindowUtil.setWindowSystemBarEnable(['status', 'navigation']).then(() => {
  ToastUtil.showToast(`设置成功!`);
}).catch((err: BusinessError) => {
  LogUtil.error(err);
});
setSpecificSystemBarEnabled 设置主窗口三键导航栏、状态栏、底部导航条的显示和隐藏
WindowUtil.setSpecificSystemBarEnabled('navigationIndicator', true).then(() => {
  ToastUtil.showToast(`设置成功!`);
}).catch((err: BusinessError) => {
  LogUtil.error(err);
});
setWindowKeepScreenOn 设置屏幕是否为常亮状态
WindowUtil.setWindowKeepScreenOn(true).then(() => {
  ToastUtil.showToast("你已设置常亮");
}).catch((err: BusinessError) => {
  LogUtil.error(err);
});
isKeepScreenOn 屏幕是否常亮
 let isKeepScreenOn = WindowUtil.isKeepScreenOn();
 ToastUtil.showToast(`屏幕是否常亮:${isKeepScreenOn}`);
setWindowBrightness 设置屏幕亮度值
WindowUtil.setWindowBrightness(0.7).then(() => {
  ToastUtil.showToast(`您已设置亮度!`);
}).catch((err: BusinessError) => {
  LogUtil.error(`异常信息-code: ${err.code} - msg: ${err.message}`)
});
getBrightness 获取屏幕亮度。该参数为浮点数,可设置的亮度范围为[0.0, 1.0],其取1.0时表示最大亮度值。如果窗口没有设置亮度值,表示亮度跟随系统,此时获取到的亮度值为-1
 let brightness = WindowUtil.getBrightness();
 ToastUtil.showToast(`屏幕亮度:${brightness}`);
setWindowFocusable 设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口
WindowUtil.setWindowFocusable(true).then(() => {
  ToastUtil.showToast("设置成功啦^·^");
}).catch((err: BusinessError) => {
  ToastUtil.showToast("设置失败!");
});
isFocusable 窗口是否可聚焦,默认主窗口
  let isFocusable = WindowUtil.isFocusable();
  ToastUtil.showToast(`窗口是否可聚焦:${isFocusable}`);
setWindowTouchable 设置窗口是否为可触状态
WindowUtil.setWindowTouchable(true).then(() => {
  ToastUtil.showToast("设置成功啦^·^");
}).catch((err: BusinessError) => {
  ToastUtil.showToast("设置失败!");
});
isTouchable 窗口是否可触摸,默认主窗口
  let isTouchable = WindowUtil.isTouchable();
  ToastUtil.showToast(`窗口是否可触摸:${isTouchable}`);
getWindowProperties 获取当前窗口的属性,默认主窗口
 let properties = WindowUtil.getWindowProperties();
 let jsonStr = `${JSON.stringify(properties, null, 2)}`;
getWindowAvoidArea 获取当前应用窗口内容规避的区域。如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域
  let area = WindowUtil.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
  let jsonStr = `${JSON.stringify(area, null, 2)}`;
getWindowType 获取窗口类型,默认主窗口
let windowType = WindowUtil.getWindowType();
getWindowStatus 获取当前应用窗口的模式
let status = WindowUtil.getWindowStatus();
isFullScreen 判断窗口是否全屏,默认主窗口
let isFullScreen = WindowUtil.isFullScreen();
isFocused 判断当前窗口是否已获焦
let isFocused = WindowUtil.isFocused();
isTransparent 窗口是否透明,默认主窗口
let isTransparent = WindowUtil.isTransparent();
isWindowShowing 判断当前窗口是否已显示,默认主窗口
let isWindowShowing = WindowUtil.isWindowShowing();
isWindowSupportWideGamut 判断当前窗口是否支持广色域模式,,默认主窗口
let isWindowSupportWideGamut = await WindowUtil.isWindowSupportWideGamut();
setDialogBackGestureEnabled 设置模态窗口是否响应手势返回事件,非模态窗口调用返回错误码
WindowUtil.setDialogBackGestureEnabled(true).then(() => {
  ToastUtil.showToast("设置成功啦^·^");
}).catch((err: BusinessError) => {
  ToastUtil.showToast("设置失败!");
});
setGestureBackEnabled 设置当前窗口是否禁用返回手势功能,仅主窗全屏模式下生效,2in1设备下不生效。
let isGestureBack = WindowUtil.isGestureBackEnabled();
WindowUtil.setGestureBackEnabled(!isGestureBack).then(() => {
  ToastUtil.showToast("设置成功啦^·^");
}).catch((err: BusinessError) => {
  ToastUtil.showToast("设置失败!");
});
isGestureBackEnabled 获取当前窗口是否禁用返回手势功能,仅主窗全屏模式下生效,2in1设备不生效。
 let isGestureBack = WindowUtil.isGestureBackEnabled();
 ToastUtil.showToast(`当前窗口是否禁用返回:${isGestureBack}`);

示例代码


import {
    router, window } from '@kit.ArkUI';
import {
    AppUtil, LogUtil, ToastUtil, WindowUtil } from '@pura/harmony-utils';
import {
    DescribeBean } from '../../model/DescribeBean';
import {
    BusinessError } from '@kit.BasicServicesKit';
import {
    MockSetup } from '@ohos/hamock';
import {
    TitleBarView } from '../../component/TitleBarView';
import {
    DialogHelper } from '@pura/harmony-dialog';
import {
    Utils } from '../../utils/Utils';
import {
    JSON } from '@kit.ArkTS';


/**
 * 窗口相关工具类
 */
@Entry
@Component
struct Index {
   
  private scroller: Scroller = new Scroller();
  @State describe: DescribeBean = router.getParams() as DescribeBean;
  @State privacyMode: boolean = false; //是否隐私模式
  @State isLayoutFullScreen: boolean = false; //是否沉浸式布局
  @State blImmersive: boolean = false; //是否开启沉浸式布局
  @State blGrayScale: boolean = false; //是否灰阶
  @State blFullScreen: boolean = false; //是否全屏
  @State isKeepScreenOn: boolean = false; //屏幕是否为常亮状态
  @State bright: number = 0.2; //屏幕亮度值
  @State blFocusable: boolean = false; //窗口是否可聚焦
  @State blTouchable: boolean = false; //窗口是否可触摸
  @State blD1: boolean = false; //模态窗口是否响应手势返回事件


  @MockSetup
  mock() {
   
    this.describe = new DescribeBean("AppUtil", "窗口相关工具类");
  }

  build() {
   
    Column() {
   
      TitleBarView({
    describe: this.describe })
      Divider()
      Scroll(this.scroller) {
   
        Column({
    space: 5 }) {
   
          Button("setPreferredOrientation()")
            .btnStyle()
            .onClick(() => {
   
              WindowUtil.setPreferredOrientation(AppUtil.isLandscape() ? window.Orientation.PORTRAIT : window.Orientation.LANDSCAPE)
                .then(() => {
   
                  ToastUtil.showToast(`设置成功!`)
                }).catch((err: BusinessError) => {
   
                  LogUtil.error(err);
                });
            })
          Button("getPreferredOrientation()")
            .btnStyle()
            .onClick(() => {
   
              let orientation = WindowUtil.getPreferredOrientation();
              DialogHelper.showToast(`窗口屏幕方向:${
     orientation}`);
            })
          Button("setWindowPrivacyMode()")
            .btnStyle()
            .onClick(() => {
   
              this.privacyMode = this.privacyMode ? false : true;
              WindowUtil.setWindowPrivacyMode(this.privacyMode).then(() => {
   
                ToastUtil.showToast(`${
     this.privacyMode ? "您已设置隐私模式,禁止截屏、录像" : "您已取消隐私模式"}`);
              }).catch((err: BusinessError) => {
   
                LogUtil.error(err);
              });
            })
          Button("isPrivacyMode()")
            .btnStyle()
            .onClick(() => {
   
              let isPrivacyMode = WindowUtil.isPrivacyMode();
              ToastUtil.showToast(`窗口是否隐私模式:${
     isPrivacyMode}`);
            })
          Button("setWindowLayoutFullScreen()")
            .btnStyle()
            .onClick(() => {
   
              this.isLayoutFullScreen = this.isLayoutFullScreen ? false : true;
              WindowUtil.setWindowLayoutFullScreen(this.isLayoutFullScreen).then(() => {
   
                ToastUtil.showToast(`沉浸式布局已设置成功!`);
              }).catch((err: BusinessError) => {
   
                LogUtil.error(err);
              });
            })
          Button("isLayoutFullScreen()")
            .btnStyle()
            .onClick(() => {
   
              let isLayoutFullScreen = WindowUtil.isLayoutFullScreen();
              ToastUtil.showToast(`窗口是否为沉浸式:${
     isLayoutFullScreen}`);
            })
          Button("setWindowSystemBarProperties()")
            .btnStyle()
            .onClick(() => {
   
              WindowUtil.setWindowSystemBarProperties({
   
                statusBarColor: '#F00FF0',
                statusBarContentColor: '#0FF00F',
                isStatusBarLightIcon: true,
                navigationBarColor: '#F06060',
                navigationBarContentColor: "#0606F0",
                isNavigationBarLightIcon: true
              }).then(() => {
   
                ToastUtil.showToast("设置成功!");
              }).catch((err: BusinessError) => {
   
                LogUtil.error(err);
              });
            })
          Button("getWindowSystemBarProperties()")
            .btnStyle()
            .onClick(() => {
   
              let properties = WindowUtil.getWindowSystemBarProperties();
              let jsonStr = JSON.stringify(properties, null, 2);
              Utils.showSheetText(jsonStr);
            })
          Button("setImmersiveModeEnabledState()")
            .btnStyle()
            .onClick(() => {
   
              this.blImmersive = this.blImmersive ? false : true;
              WindowUtil.setImmersiveModeEnabledState(this.blImmersive);
              ToastUtil.showToast("设置成功!");
            })
          Button("getImmersiveModeEnabledState()")
            .btnStyle()
            .onClick(() => {
   
              let enabled = WindowUtil.getImmersiveModeEnabledState();
              ToastUtil.showToast(`是否开启沉浸式布局:${
     enabled}`);
            })
          Button("setWindowGrayScale()")
            .btnStyle()
            .onClick(() => {
   
              this.blGrayScale = !this.blGrayScale;
              let grayScale = this.blGrayScale ? 1.0 : 0;
              WindowUtil.setWindowGrayScale(grayScale);
              ToastUtil.showToast(`窗口灰阶:${
     grayScale}`);
            })
          Button("setWindowBackgroundColor()")
            .btnStyle()
            .onClick(() => {
   
              WindowUtil.setWindowBackgroundColor('#9932CC');
              ToastUtil.showToast("设置背景色成功!");
            })
          Button("setWindowSystemBarEnable()")
            .btnStyle()
            .onClick(() => {
   
              this.blFullScreen = !this.blFullScreen;
              WindowUtil.setWindowSystemBarEnable(this.blFullScreen ? [] : ['status', 'navigation']).then(() => {
   
                ToastUtil.showToast(`设置成功!`);
              }).catch((err: BusinessError) => {
   
                LogUtil.error(err);
              });
            })
          Button("setSpecificSystemBarEnabled()")
            .btnStyle()
            .onClick(() => {
   
              let name: window.SpecificSystemBar = this.blFullScreen ? 'status' : 'navigationIndicator';
              WindowUtil.setSpecificSystemBarEnabled(name, this.blFullScreen).then(() => {
   
                ToastUtil.showToast(`设置成功!`);
              }).catch((err: BusinessError) => {
   
                LogUtil.error(err);
              });
            })
          Button("setWindowKeepScreenOn()")
            .btnStyle()
            .onClick(() => {
   
              this.isKeepScreenOn = this.isKeepScreenOn ? false : true;
              WindowUtil.setWindowKeepScreenOn(this.isKeepScreenOn).then(() => {
   
                ToastUtil.showToast(`${
     this.isKeepScreenOn ? "你已设置常亮" : "你已取消常亮"}`);
              }).catch((err: BusinessError) => {
   
                LogUtil.error(err);
              });
            })
          Button("isKeepScreenOn()")
            .btnStyle()
            .onClick(() => {
   
              let isKeepScreenOn = WindowUtil.isKeepScreenOn();
              ToastUtil.showToast(`屏幕是否常亮:${
     isKeepScreenOn}`);
            })
          Button("setWindowBrightness()")
            .btnStyle()
            .onClick(() => {
   
              this.bright = this.bright === 1.0 ? 0.2 : 1.0;
              WindowUtil.setWindowBrightness(this.bright).then(() => {
   
                ToastUtil.showToast(`您已设置亮度: ${
     this.bright}`);
              }).catch((err: BusinessError) => {
   
                LogUtil.error(`异常信息-code: ${
     err.code} - msg: ${
     err.message}`)
              });
            })
          Button("getBrightness()")
            .btnStyle()
            .onClick(() => {
   
              let brightness = WindowUtil.getBrightness();
              ToastUtil.showToast(`屏幕亮度:${
     brightness}`);
            })
          Button("setWindowFocusable()")
            .btnStyle()
            .onClick(() => {
   
              this.blFocusable = !this.blFocusable;
              WindowUtil.setWindowFocusable(this.blFocusable).then(() => {
   
                ToastUtil.showToast("设置成功啦^·^");
              }).catch((err: BusinessError) => {
   
                ToastUtil.showToast("设置失败!");
              });
            })
          Button("isFocusable()")
            .btnStyle()
            .onClick(() => {
   
              let isFocusable = WindowUtil.isFocusable();
              ToastUtil.showToast(`窗口是否可聚焦:${
     isFocusable}`);
            })
          Button("setWindowTouchable()")
            .btnStyle()
            .onClick(() => {
   
              this.blTouchable = !this.blTouchable;
              WindowUtil.setWindowTouchable(this.blTouchable).then(() => {
   
                ToastUtil.showToast("设置成功啦^·^");
              }).catch((err: BusinessError) => {
   
                ToastUtil.showToast("设置失败!");
              });
            })
          Button("isTouchable()")
            .btnStyle()
            .onClick(() => {
   
              let isTouchable = WindowUtil.isTouchable();
              ToastUtil.showToast(`窗口是否可触摸:${
     isTouchable}`);
            })
          Button("getWindowProperties()")
            .btnStyle()
            .onClick(() => {
   
              let properties = WindowUtil.getWindowProperties();
              let jsonStr = `${
     JSON.stringify(properties, null, 2)}`;
              Utils.showSheetText(jsonStr);
            })
          Button("getWindowAvoidArea()")
            .btnStyle()
            .onClick(() => {
   
              let area = WindowUtil.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
              let jsonStr = `${
     JSON.stringify(area, null, 2)}`;
              Utils.showSheetText(jsonStr);
            })
          Button("getWindowType()\ngetWindowStatus()\nisTransparent()\nisFullScreen()\nisTransparent()\nisWindowShowing()\nisWindowSupportWideGamut()")
            .labelStyle({
    maxLines: 8 })
            .type(ButtonType.Normal)
            .borderRadius(10)
            .padding({
    top: 10, bottom: 10 })
            .btnStyle()
            .onClick(async () => {
   
              let windowType = WindowUtil.getWindowType();
              let status = WindowUtil.getWindowStatus();
              let isFocused = WindowUtil.isFocused();
              let isFullScreen = WindowUtil.isFullScreen();
              let isTransparent = WindowUtil.isTransparent();
              let isWindowShowing = WindowUtil.isWindowShowing();
              let isWindowSupportWideGamut = await WindowUtil.isWindowSupportWideGamut();
              let textStr = `windowType: ${
     windowType}\nWindowStatus: ${
     status}\nisFocused: ${
     isFocused}\nisFullScreen: ${
     isFullScreen}`;
              textStr = textStr + `\nisTransparent: ${
     isTransparent}\nisWindowShowing: ${
     isWindowShowing}\nisWindowSupportWideGamut: ${
     isWindowSupportWideGamut}`;
              Utils.showSheetText(textStr);
            })
          Button("setDialogBackGestureEnabled()")
            .btnStyle()
            .onClick(() => {
   
              this.blD1 = !this.blD1;
              WindowUtil.setDialogBackGestureEnabled(this.blD1).then(() => {
   
                ToastUtil.showToast("设置成功啦^·^");
              }).catch((err: BusinessError) => {
   
                ToastUtil.showToast("设置失败!");
              });
            })
          Button("setGestureBackEnabled()")
            .btnStyle()
            .onClick(() => {
   
              let isGestureBack = WindowUtil.isGestureBackEnabled();
              WindowUtil.setGestureBackEnabled(!isGestureBack).then(() => {
   
                ToastUtil.showToast("设置成功啦^·^");
              }).catch((err: BusinessError) => {
   
                ToastUtil.showToast("设置失败!");
              });
            })
          Button("isGestureBackEnabled()")
            .btnStyle()
            .onClick(() => {
   
              let isGestureBack = WindowUtil.isGestureBackEnabled();
              ToastUtil.showToast(`当前窗口是否禁用返回:${
     isGestureBack}`);
            })
        }
        .margin({
    top: 5, bottom: 5 })
      }
      .layoutWeight(1)
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Start)
    .backgroundColor($r('app.color.main_background'))
  }
}


@Styles
function btnStyle() {
   
  .width('90%')
  .margin({
    top: 10, bottom: 5 })
}

创作不易,请给童长老点赞👍


https://github.com/787107497/harmony-utils
https://gitee.com/tongyuyan/harmony-utils
OpenHarmony三方库
童长老CSDN博客

目录
相关文章
|
Apache 开发者
最受欢迎的三方库之SpinKit
SpinKit 是一款适用于 OpenHarmony/HarmonyOS 的加载动画库,提供多种动画类型与自定义配置,帮助开发者轻松实现美观的加载效果。
334 0
|
存储 JSON 生物认证
harmony-utils之AssetUtil,关键资产存储服务工具类
AssetUtil 是 harmony-utils 工具库中的关键资产存储服务工具类,提供新增、查询、删除资产等功能,支持同步与异步操作,适用于 HarmonyOS 应用开发。
290 0
|
JSON 生物认证 API
harmony-utils之RegexUtil,正则工具类
RegexUtil 是 harmony-utils 中的正则工具类,提供多种常用正则验证方法,如验证手机号、邮箱、身份证、数字、URL 等。支持快速判断字符串是否匹配特定格式,助力 HarmonyOS 开发高效便捷。
323 0
|
JSON 前端开发 生物认证
harmony-utils之SnapshotUtil,截图相关工具类
harmony-utils是一款专为HarmonyOS开发的高效工具库,提供丰富的实用功能,助力开发者快速构建鸿蒙应用。其中的SnapshotUtil类专注于截图功能,支持组件截图、自定义Builder渲染截图、窗口截图及系统截屏监听等操作,极大提升了开发效率与应用交互体验。
309 0
|
iOS开发
harmony-dialog预览效果
harmony-dialog 是一款简单易用、零侵入的弹窗组件,支持多种类型如确认框、提示框、输入框、选择器、加载框等,覆盖常见开发需求。
359 0
harmony-dialog预览效果
鸿蒙NEXT-HMRouter,在使用router后无法跳转问题解决
作者在使用HMRouter搭建鸿蒙三层架构App时,遇到登录页跳转首页后无法继续跳转的问题。经排查发现,错误原因是在onVisibleAreaChange中直接跳转导致页面生命周期冲突。解决方案是将跳转逻辑移至页面生命周期回调如aboutToAppear中执行,从而确保路由状态正常,成功修复Bug。
533 0
|
JSON 安全 Java
鸿蒙5开发宝藏案例分享---应用并发设计
本文深入解析鸿蒙并发编程,基于ArkTS多线程模型提供100+实战解决方案。从图片解码加速到折叠屏适配,涵盖生产者-消费者模式与性能调优技巧。文章剖析传统并发痛点,介绍ArkTS的内存隔离、异步I/O和自动扩缩容三大核心理念,并通过代码示例讲解实际场景应用。同时警示常见陷阱如Worker线程泄漏与跨线程修改共享对象,提供安全方案及性能优化工具,助力开发者高效掌握鸿蒙并发开发最佳实践。
|
JSON API Apache
最受欢迎的三方库之china_area
`@nutpi/china_area` 是一款提供中国省、市、县三级区域数据的 OpenHarmony 工具库,支持同步与异步调用方式,便于快速集成至鸿蒙应用中。配套 `@pura/harmony-utils` 与 `@pura/harmony-dialog` 可实现高效开发,如地区选择器等交互功能。API 简洁易用,附有完整示例代码,助力开发者提升效率。项目遵循 Apache License 2.0 协议,欢迎参与共建。
323 0
|
API Apache 开发者
最受欢迎的三方库之EventBus
EventBus 是一款支持 Sticky 和跨 App 广播的消息总线,适用于 HarmonyOS 开发。提供丰富的 API,如事件监听、消息发布等,助力高效构建应用。
327 0
|
JSON 生物认证 API
harmony-utils之AuthUtil,生物认证相关工具类
harmony-utils之AuthUtil是一个生物认证工具类,支持人脸识别、指纹、密码等多种认证方式。提供认证能力查询、开始/取消认证、生成挑战值等功能,适用于HarmonyOS应用开发,提升安全性与用户体验。
275 0