User authorization is required before certain APIs are used. These APIs are divided into multiple scopes based on their usage. When a user grants authorization for a scope, all the APIs corresponding to 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 application cannot obtain the authorization, resulting in the failure of API calls. For details about the permission declaration fields in the configuration file, see Declaring Permissions in the Configuration File.
Before the related service functionality is executed, initiate a request for user authorization. Once the user has explicitly granted or rejected the authorization, the authorization result is recorded in the background until the user deletes the atomic service.
The following situations may occur when such APIs are called:
The authorization dialog box displays the permission usage declared in the privacy statement of the atomic service. The permission usage must comply with Specifications for reason.
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.log("openSetting success.");
}
}); Call has.authorize to initiate a request for user authorization before the related API is called.
has.authorize({
scope: 'scope.userLocation',
success() {}
}); Before initiating a request for user authorization, you must declare the permissions required in the application configuration file. For details, see Declaring Permissions.
Scope | APIs | Description | Required Permissions |
|---|---|---|---|
scope.userLocation | Precise geographical location | ohos.permission.LOCATION, ohos.permission.APPROXIMATELY_LOCATION | |
scope.userFuzzyLocation | Approximate location | ohos.permission.APPROXIMATELY_LOCATION | |
scope.camera | camera component | Camera | ohos.permission.CAMERA |
scope.addPhoneCalendar | 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 | Microphone | ohos.permission.MICROPHONE |