harmony-utils之WantUtil,Want工具類
harmony-utils 簡介與說明
[harmony-utils] 一款功能豐富且極易上手的HarmonyOS工具庫,借助眾多實(shí)用工具類,致力于助力開發(fā)者迅速構(gòu)建鴻蒙應(yīng)用。其封裝的工具涵蓋了APP、設(shè)備、屏幕、授權(quán)、通知、線程間通信、彈框、吐司、生物認(rèn)證、用戶首選項(xiàng)、拍照、相冊、掃碼、文件、日志,異常捕獲、字符、字符串、數(shù)字、集合、日期、隨機(jī)、base64、加密、解密、JSON等一系列的功能和操作,能夠滿足各種不同的開發(fā)需求。
[picker_utils] 是harmony-utils拆分出來的一個(gè)子庫,包含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方法與使用
toSetting 跳轉(zhuǎn)系統(tǒng)設(shè)置頁面(配合WantUtil里的URI常量一起使用,可跳轉(zhuǎn)更多的設(shè)置頁面)
WantUtil.toSetting(WantUtil.URI_BIOMETRICS_AND_PASSWORD); //跳轉(zhuǎn)生物識(shí)別和密碼
WantUtil.toSetting(WantUtil.URI_ABOUT_DEVICE); //跳轉(zhuǎn)關(guān)于本機(jī)界面
WantUtil.toSetting(WantUtil.URI_SYSTEM_AND_UPDATES); //系統(tǒng)和更新
WantUtil.toSetting(WantUtil.URI_DISPLAY); //顯示和亮度
WantUtil.toSetting(WantUtil.URI_ACCESSIBILITY_FEATURE); //輔助功能
WantUtil.toSetting(WantUtil.URI_APPLICATION_AND_SERVICE); //應(yīng)用與元服務(wù)
toAppSetting 跳轉(zhuǎn)應(yīng)用設(shè)置頁面
WantUtil.toAppSetting();
toNotificationSetting 跳轉(zhuǎn)通知設(shè)置頁面
WantUtil.toNotificationSetting();
toNetworkSetting 跳轉(zhuǎn)移動(dòng)網(wǎng)絡(luò)設(shè)置頁面
WantUtil.toNetworkSetting();
toWifiSetting 跳轉(zhuǎn)WLAN設(shè)置頁面
WantUtil.toWifiSetting();
toBluetoothSetting 跳轉(zhuǎn)藍(lán)牙設(shè)置頁面
WantUtil.toBluetoothSetting();
toNfcSetting 跳轉(zhuǎn)NFC設(shè)置頁面
WantUtil.toNfcSetting();
toVolumeSetting 跳轉(zhuǎn)聲音和振動(dòng)設(shè)置頁面
WantUtil.toVolumeSetting();
toStorageSetting 跳轉(zhuǎn)存儲(chǔ)設(shè)置頁面
WantUtil.toStorageSetting();
toBatterySetting 跳轉(zhuǎn)電池設(shè)置頁面
WantUtil.toBatterySetting();
toWebBrowser 拉起系統(tǒng)瀏覽器
WantUtil.toWebBrowser("https://developer.huawei.com/")
.catch((err: BusinessError) = > {
LogUtil.error(JSON.stringify(err));
ToastUtil.showToast("拉起失??!");
});
toAppGalleryDetail 拉起應(yīng)用市場對應(yīng)的應(yīng)用詳情界面
WantUtil.toAppGalleryDetail("com.harmony.utils")
.catch((err: BusinessError) = > {
LogUtil.error(JSON.stringify(err));
ToastUtil.showToast("拉起失?。?);
});
toFileManagement 拉起系統(tǒng)文件管理器
WantUtil.toFileManagement()
.catch((err: BusinessError) = > {
LogUtil.error(JSON.stringify(err));
ToastUtil.showToast("拉起失?。?);
});
startMMS 拉起短信界面并指定聯(lián)系人
WantUtil.startMMS("13909626520", "張三").then(() = > {
ToastUtil.showToast("拉起短信界面…")
}).catch((err: BusinessError) = > {
LogUtil.error(JSON.stringify(err));
ToastUtil.showToast("拉起失敗!");
});
openFile 調(diào)用三方軟件打開文件
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}`);
});
創(chuàng)作不易,請給童長老點(diǎn)贊
審核編輯 黃宇
-
Harmony
+關(guān)注
關(guān)注
0文章
108瀏覽量
3021
發(fā)布評論請先 登錄
評論