目录

Authorization

User authorization is required before certain APIs are used. These APIs are divided into multiple scopes based on their use cases. When a user grants authorization for a scope, all APIs under that scope can be called.

The permissions required for calling the APIs must be declared one by one in the project configuration file. Otherwise, the atomic service cannot obtain the authorization, resulting in the failure of API calls. For details about the permission declaration fields in the configuration file, please refer to Declaring Permissions in the Configuration File.

Before the related service functionality is executed, initiate a request for user authorization. After the user explicitly grants or rejects authorization, the authorization result is recorded in the backend and persists until the user deletes the atomic service.

The following situations may occur when APIs requiring user authorization are called:

The authorization dialog displays the permission usage declared in the user privacy protection guide of the atomic service. The permission usage description must comply with Specifications for reason.

Requesting Permissions

[h2]Guiding Users to Grant Permissions in Settings

Users can choose Settings > Manage service of an atomic service to set the permissions for the atomic service.

Call has.openSetting to open the Settings page and guide the user to set permissions.

has.openSetting({
  success: (res) => {
    console.info('openSetting success', res);
  },
  fail: (err) => {
    console.error('openSetting fail', err);
  },
  complete: (res) => {
    console.info('openSetting complete', res);
  }
});

[h2]Initiating a Request for User Authorization

Call has.authorize to initiate a request for user authorization before the related API is called.

has.authorize({
  scope: 'scope.userLocation',
  success: (res) => {
    console.info('authorize success', res);
  },
  fail: (err) => {
    console.error('authorize fail', err);
  },
  complete: (res) => {
    console.info('authorize complete', res);
  }
});

Scope List

Before initiating a request for user authorization, you must declare the permissions required in the app configuration file. For details, please refer to Declaring Permissions.

Scope API Description Required Permission
scope.userLocation

has.getLocation

MapContext.moveToLocation

has.onWifiConnected

has.getWifiList

has.getConnectedWifi

has.connectWifi

Precise geographical location

ohos.permission.LOCATION

ohos.permission.APPROXIMATELY_LOCATION

scope.userFuzzyLocation

has.getFuzzyLocation

has.startLocationUpdate

has.startLocationUpdateBackground

Approximate geographical location ohos.permission.APPROXIMATELY_LOCATION
scope.camera

camera component

CameraContext.takePhoto

CameraContext.startRecord

has.startLivenessDetection

Camera ohos.permission.CAMERA
scope.addPhoneCalendar

has.addPhoneCalendar

has.addPhoneRepeatCalendar

Adding events to the calendar

ohos.permission.READ_CALENDAR

ohos.permission.WRITE_CALENDAR

scope.bluetooth

All APIs in Bluetooth - General

All APIs in Bluetooth - BLE

Bluetooth ohos.permission.ACCESS_BLUETOOTH
scope.record

camera component

CameraContext.startRecord

CameraContext.takePhoto

has.startRecord

RecorderManager.start

RecorderManager.pause

RecorderManager.resume

RecorderManager.stop

Microphone ohos.permission.MICROPHONE