Introduction and description of harmony-utils
harmony-utils A HarmonyOS tool library with rich features and extremely easy to use, with the help of many practical tools, is committed to helping developers quickly build Hongmeng applications. Its encapsulated tools cover APP, device, screen, authorization, notification, inter-thread communication, pop-up frames, toast, biometric authentication, user preferences, taking photos, albums, scanning codes, files, logs, exception capture, characters, strings, numbers, collections, dates, random, base64, encryption, decryption, JSON and other functions, which can meet various development needs.
picker_utils It is a sub-store split by harmony-utils, including PickerUtil, PhotoHelper, and ScanUtil.
Download and install
ohpm i @pura/harmony-utils
ohpm i @pura/picker_utils
//Global initialization method, initialized in the onCreate method of UIAbility AppUtil.init()
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
AppUtil.init(this.context);
}
API methods and usage
canIUse Whether the current device supports this module
let canIUse = AssetUtil.canIUse();
ToastUtil.showToast(`当前设备是否支持该模块:${canIUse}`);
add a new key asset
AssetUtil.add("key_harmony", "我是异步知产X!").then(() => {
ToastUtil.showToast(`新增资产成功!`);
});
AssetUtil.addSync("key_harmony_sync", "我是同步知产X!");
ToastUtil.showToast(`新增资产成功!`);
get query key assets
let rStr = await AssetUtil.get("key_harmony");
ToastUtil.showToast(`取值: ${rStr}`);
let sStr = AssetUtil.getSync("key_harmony_sync");
ToastUtil.showToast(`同步:${sStr}`);
remove key assets
AssetUtil.remove("key_harmony").then(() => {
ToastUtil.showToast("移除成功!");
});
AssetUtil.removeSync("key_harmony_sync");
ToastUtil.showToast("移除成功!");
Top comments (0)