HarmonyOS 鸿蒙Next 打开 “访问我的位置”
HarmonyOS 鸿蒙Next 打开 “访问我的位置”
用户把“访问我的位置”关了,geoLocationManager.isLocationEnabled();返回 false时,提醒用户打开“访问我的位置”,怎么跳转到“访问我的位置”页面(设置–隐私与安全–位置–访问我的位置)
3 回复
需要申请 ohos.permission.GRANT_SENSITIVE_PERMISSIONS权限 您尝试下以下demo是否可以:
import common from '@ohos.app.ability.common';
import Want from '@ohos.app.ability.Want';
@Entry
@Component
struct Index6 {
@State message: string = 'Hello World';
build() {
Row() {
Column() {
Button("to访问我的位置信息").onClick(()=>{
let context = getContext(this) as common.UIAbilityContext;
let want: Want = {
bundleName: 'com.huawei.hmos.settings',
abilityName: 'com.huawei.hmos.settings.MainAbility',
uri: "location_manager_settings",
};
console.log("want",want)
context.startAbility(want)
}).margin(10)
}
.width('100%')
}
.height('100%')
}
}
更多关于HarmonyOS 鸿蒙Next 打开 “访问我的位置”的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
import { abilityAccessCtrl, bundleManager, common, Permissions } from '@kit.AbilityKit';
import { notificationManager } from '@kit.NotificationKit';
openPermissionSettingsInSettingPage() {
// 1. 获取应用上下文,并通过 as 断言收窄类型为 UIAbilityContext,否则 context 默认类型无法调用 startAbility 方法
const context = getContext() as common.UIAbilityContext
// 2. 获取 bundle 包信息
const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
// 3. 通过 startAbility 打开 系统设置 页
context.startAbility({
bundleName: 'com.huawei.hmos.settings', // 固定写法CV:设置页的包名
abilityName: 'com.huawei.hmos.settings.MainAbility', // 固定写法CV:设置页的 ability 名
uri: 'application_info_entry', // 固定写法CV:打开 设置->应用和元服务
parameters: {
// 打开指定应用(包)的详情页面
// pushParams: 'com.itheima.hm_guardian'
// 应用包名可通过 bundleManager 动态获取
pushParams: bundleInfo.name
}
})
}
openPermissionSettingsInSettingPage() // 掉这个方法 试试