HarmonyOS 位置信息设置及跳转?

1、如何判断‘访问我的位置信息’是否允许

2、如何代码跳转系统‘位置信息’页面

阅读 535
1 个回答

1、判断位置开关是否开启:geoLocationManager.isLocationEnabled

参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-geolocationmanager-V5\#geolocationmanagerislocationenabled

2、拉起方需要申请 ohos.permission.GRANT\_SENSITIVE\_PERMISSIONS权限

参考DEMO如下:

import { common } from '@kit.AbilityKit';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  openAppInfo() {
    let context = getContext(this) as common.UIAbilityContext;
    context.startAbility({
      bundleName: 'com.huawei.hmos.settings',
      abilityName: 'com.huawei.hmos.settings.MainAbility',
      uri: 'application_info_entry',
      parameters: {
        pushParams: "com.example.uiabilitycontext"
      }
    });
  }

  build() {
    Row() {
      Column() {
        Button('123').onClick(() => {
          this.openAppInfo()
        })
      }
      .width('100%')
    }
    .height('100%')
  }
}

pushParams: "com.example.uiabilitycontext"这个是具体的app名称,可查看app.json5文件

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进