代码拉取完成,页面将自动刷新
import { router } from '@kit.ArkUI';
import { MockSetup } from '@ohos/hamock';
import { FileUtil, LogUtil, ToastUtil, WantUtil } from '@pura/harmony-utils';
import { DescribeBean } from '../../model/DescribeBean';
import { BusinessError } from '@kit.BasicServicesKit';
import { TitleBarView } from '../../component/TitleBarView';
/**
* Want工具类
*/
@Entry
@Component
struct Index {
private scroller: Scroller = new Scroller();
@State describe: DescribeBean = router.getParams() as DescribeBean;
@State docPath: string = '' //文件路径
@MockSetup
mock() {
this.describe = new DescribeBean("WantUtil", "Want工具类");
}
async aboutToAppear(): Promise<void> {
this.docPath = FileUtil.getFilesDirPath('download/wps/doc', '测试DOC文件.doc');
FileUtil.writeEasy(this.docPath, "harmony-utils 一款高效的OpenHarmony/HarmonyOS工具包。帮助开发者快速构建鸿蒙应用。哈哈哈哈哈哈!");
}
build() {
Column() {
TitleBarView({ describe: this.describe })
Divider()
Scroll(this.scroller) {
Column() {
Button("toAppSetting()")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("跳转应用设置页面!");
WantUtil.toAppSetting();
})
Button("toNotificationSetting()")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("跳转通知设置页面!");
WantUtil.toNotificationSetting();
})
Button("toNetworkSetting()")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("跳转移动网络设置页面!");
WantUtil.toNetworkSetting();
})
Button("toWifiSetting()")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("跳转WLAN设置页面!");
WantUtil.toWifiSetting();
})
Button("toBluetoothSetting()")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("跳转蓝牙设置页面!");
WantUtil.toBluetoothSetting();
})
Button("toNfcSetting()")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("跳转NFC设置页面!");
WantUtil.toNfcSetting();
})
Button("toVolumeSetting()")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("跳转声音和振动设置页面!");
WantUtil.toVolumeSetting();
})
Button("toStorageSetting()")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("跳转存储设置页面!");
WantUtil.toStorageSetting();
})
Button("toBatterySetting()")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("跳转电池设置页面!")
WantUtil.toBatterySetting();
})
Button("toSetting(),URI_BIOMETRICS_AND_PASSWORD")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("跳转生物识别和密码!");
WantUtil.toSetting(WantUtil.URI_BIOMETRICS_AND_PASSWORD);
})
Button("toSetting(),URI_ABOUT_DEVICE")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("跳转关于本机界面!");
WantUtil.toSetting(WantUtil.URI_ABOUT_DEVICE);
})
Button("toWebBrowser()")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("拉起系统浏览器中…")
WantUtil.toWebBrowser("https://developer.huawei.com/")
.catch((err: BusinessError) => {
LogUtil.error(JSON.stringify(err));
ToastUtil.showToast("拉起失败!");
});
})
Button("toAppGalleryDetail()")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("拉起应用市场对应的应用详情界面中…")
WantUtil.toAppGalleryDetail("com.harmony.utils")
.catch((err: BusinessError) => {
LogUtil.error(JSON.stringify(err));
ToastUtil.showToast("拉起失败!");
});
})
Button("toFileManagement()")
.btnStyle()
.onClick(() => {
ToastUtil.showToast("拉起系统文件管理器中…")
WantUtil.toFileManagement()
.catch((err: BusinessError) => {
LogUtil.error(JSON.stringify(err));
ToastUtil.showToast("拉起失败!");
});
})
Button("startMMS()")
.btnStyle()
.onClick(() => {
WantUtil.startMMS("13909626520", "张三").then(() => {
ToastUtil.showToast("拉起短信界面…")
}).catch((err: BusinessError) => {
LogUtil.error(JSON.stringify(err));
ToastUtil.showToast("拉起失败!");
});
})
Button("openFile()")
.btnStyle()
.onClick(() => {
let uri = FileUtil.getUriFromPath(this.docPath);
LogUtil.error("uri: "+ uri)
WantUtil.openFile(uri).catch((error: BusinessError) => {
ToastUtil.showToast("打开文件失败," + error.message);
LogUtil.error(`打开文件异常 ~ code: ${error.code} -·- message: ${error.message}`);
});
})
Blank().layoutWeight(1)
}
.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: 2 })
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。