中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
打开授权设置页Button的实现
微信扫码分享
// OpenSetting.ets import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @Entry @Component struct Index { build() { Row() { Column() { // 声明FunctionalButton FunctionalButton({ params: { // OpenType.OPEN_SETTING表示Button为打开授权设置页类型 openType: functionalButtonComponentManager.OpenType.OPEN_SETTING, label: '打开授权设置页', // 调整Button样式 styleOption: { styleConfig: new functionalButtonComponentManager.ButtonConfig() .fontSize(20) .fontColor(Color.Black) } }, // OpenType为“OPEN_SETTING”时,回调必须选择“onOpenSetting” controller: new functionalButtonComponentManager.FunctionalButtonController().onOpenSetting((err, data) => { if (err) { // 错误日志处理 hilog.error(0x0000, "testTag", "error: %{public}d %{public}s", err.code, err.message); return; } // 成功日志处理终止设置应用程序时触发 hilog.info(0x0000, "testTag", "succeeded in opening setting"); data.permissions!.forEach((value, key) => { hilog.info(0x0000, "testTag", "key: %{public}s value: %{public}s", String(key), value); }) }) }) }.width('100%') }.height('100%') } }