一、通过弹窗点击设置跳转系统应用能力
1、 自定义弹窗效果图
2、 自定义弹窗代码
import { common, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
export function alertDialog() {
AlertDialog.show({
title: '',
message: '当前功能依赖定位权限,拒绝授权将无法使用此功能。您可以在系统设置中打开定位权限,从而重新启用功能。',
autoCancel: true,
alignment: DialogAlignment.Bottom,
gridCount: 4,
offset: { dx: 0, dy: -20 },
primaryButton: {
value: '取消',
action: () => {
console.info('Callback when the first button is clicked')
}
},
secondaryButton: {
value: '设置',
action: () => {
console.info('Callback when the second button is clicked')
let wantInfo: Want = {
bundleName: 'com.huawei.hmos.settings',
abilityName: 'com.huawei.hmos.settings.MainAbility',
uri: 'location_manager_settings',
parameters: {
pushParams: 'com.example.myapplication' // 打开指定应用的详情页面
}
}
let context = 项目单例context或者参数传入 getContext(this) as common.UIAbilityContext;
context.startAbility(wantInfo).then((data) => {
}).catch((err: BusinessError) => {
// ...
})
}
},
cancel: () => {
console.info('Closed callbacks')
}
})
}
二、跳转系统不同应用能力
隐私与安全-位置信息
// 隐私与安全-位置信息
let wantInfo: Want = {
bundleName: 'com.huawei.hmos.settings',
abilityName: 'com.huawei.hmos.settings.MainAbility',
uri: 'location_manager_settings',
};
应用权限设置
// 应用权限设置
let wantInfo: Want = {
bundleName: 'com.huawei.hmos.settings',
abilityName: 'com.huawei.hmos.settings.WifiSettingsAbility',
uri: 'application_info_entry',
};
跳转wifi设置
// 跳转wifi设置
let wantInfo: want = {
bundleName: 'com.huawei.hmos.settings',
abilityName: 'com.huawei.hmos.settings.WifiSettingsAbility',
action: 'action.settings.wifi',
};
应用和元服务
// 应用和元服务
let wantInfo: want = {
bundleName: 'com.huawei.hmos.settings',
abilityName: 'com.huawei.hmos.settings.MainAbility',
uri: 'application_settings',
};
通知管理页面
// 通知管理页面
let wantInfo: Want = {
bundleName: 'com.huawei.hmos.settings', // 设置应用bundleName
abilityName: 'com.huawei.hmos.settings.MainAbility', // 设置应用abilityName
uri: "systemui_notification_settings", // 通知管理页面
parameters: {
pushParams: {
bundleName:context.abilityInfo.bundleName //拉起方应用包名
}
};
进入设置-应用详情页
// 进入设置-应用详情页
let wantInfo: want = {
bundleName: 'com.huawei.hmos.settings',
abilityName: 'com.huawei.hmos.settings.MainAbility',
uri: 'application_info_entry',
parameters: {
pushParams: "com.example.startability" // 换成项目包名
}
};
蓝牙
// 蓝牙
let wantInfo: want = {
bundleName: 'com.huawei.hmos.settings',
abilityName: 'com.huawei.hmos.settings.MainAbility',
uri: 'bluetooth_entry',
parameters: {
pushParams: "com.example.startability" // 换成项目包名
}
};
NFC
// NFC
let wantInfo: want = {
bundleName: 'com.huawei.hmos.settings',
abilityName: 'com.huawei.hmos.settings.MainAbility',
uri: 'nfc_settings',
parameters: {
pushParams: "com.example.startability" // 换成项目包名
}
};
移动网络
// 移动网络
let wantInfo: want = {
bundleName: 'com.huawei.hmos.settings',
abilityName: 'com.huawei.hmos.settings.MainAbility',
uri: 'mobile_network_entry',
parameters: {
pushParams: "com.example.startability" // 换成项目包名
}
};
三、参考华为文档
文档中心https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/request-user-authorization-0000001774279718