WantUtil, Want tool class

WantUtil, Want tool class

Publish Date: Jun 29
0 0

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);
  }
Enter fullscreen mode Exit fullscreen mode

API methods and usage


toSetting jumps to the system settings page (used with the URI constants in WantUtil to jump to more settings pages)
 WantUtil.toSetting(WantUtil.URI_BIOMETRICS_AND_PASSWORD); //跳转生物识别和密码
 WantUtil.toSetting(WantUtil.URI_ABOUT_DEVICE); //跳转关于本机界面
 WantUtil.toSetting(WantUtil.URI_SYSTEM_AND_UPDATES); //系统和更新
 WantUtil.toSetting(WantUtil.URI_DISPLAY); //显示和亮度
 WantUtil.toSetting(WantUtil.URI_ACCESSIBILITY_FEATURE); //辅助功能
 WantUtil.toSetting(WantUtil.URI_APPLICATION_AND_SERVICE); //应用与元服务
Enter fullscreen mode Exit fullscreen mode
toAppSetting Jump toAppSetting
WantUtil.toAppSetting();
Enter fullscreen mode Exit fullscreen mode
toNotificationSetting Jump Notification Setting Page
 WantUtil.toNotificationSetting();
Enter fullscreen mode Exit fullscreen mode
toNetworkSetting Jump to the mobile network settings page
 WantUtil.toNetworkSetting();
Enter fullscreen mode Exit fullscreen mode
toWifiSetting Jump to WLAN Settings Page
 WantUtil.toWifiSetting();
Enter fullscreen mode Exit fullscreen mode
toBluetoothSetting Jump to Bluetooth Settings Page
 WantUtil.toBluetoothSetting();
Enter fullscreen mode Exit fullscreen mode
toNfcSetting Jump to NFC Settings Page
 WantUtil.toNfcSetting();
Enter fullscreen mode Exit fullscreen mode
toVolumeSetting Jump Sound and Vibration Settings Page
WantUtil.toVolumeSetting();
Enter fullscreen mode Exit fullscreen mode
toStorageSetting Jump Storage Settings Page
WantUtil.toStorageSetting();
Enter fullscreen mode Exit fullscreen mode
toBatterySetting Jump Battery Settings Page
 WantUtil.toBatterySetting(); 
Enter fullscreen mode Exit fullscreen mode
toWebBrowser Pull up the system browser
WantUtil.toWebBrowser("https://developer.huawei.com/")
  .catch((err: BusinessError) => {
    LogUtil.error(JSON.stringify(err));
    ToastUtil.showToast("拉起失败!");
  });
Enter fullscreen mode Exit fullscreen mode
toAppGalleryDetail pulls up the application details interface corresponding to the application market
WantUtil.toAppGalleryDetail("com.harmony.utils")
  .catch((err: BusinessError) => {
    LogUtil.error(JSON.stringify(err));
    ToastUtil.showToast("拉起失败!");
  });
Enter fullscreen mode Exit fullscreen mode
toFileManagement Pull up the system file manager
WantUtil.toFileManagement()
  .catch((err: BusinessError) => {
    LogUtil.error(JSON.stringify(err));
    ToastUtil.showToast("拉起失败!");
  });
Enter fullscreen mode Exit fullscreen mode
startMMS pull up the SMS interface and specify the contact person
WantUtil.startMMS("13909626520", "张三").then(() => {
  ToastUtil.showToast("拉起短信界面…")
}).catch((err: BusinessError) => {
  LogUtil.error(JSON.stringify(err));
  ToastUtil.showToast("拉起失败!");
});
Enter fullscreen mode Exit fullscreen mode
openFile calls three-party software to open the file
let docPath = FileUtil.getFilesDirPath('download/wps/doc', '测试DOC文件.doc');
let uri = FileUtil.getUriFromPath(docPath);
WantUtil.openFile(uri).catch((error: BusinessError) => {
  ToastUtil.showToast("打开文件失败," + error.message);
  LogUtil.error(`打开文件异常 ~ code: ${error.code} -·- message: ${error.message}`);
});
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment