has.setVisualEffectOnCapture(Object object)
Sets the screen performance during screenshot/screen recording, and disables screenshot/screen recording for atomic service windows. The setting takes effect only when the current atomic service is in the foreground. For other atomic services or windows that are not configured, it does not take effect.
Since: 2.0.1
Required permission: ohos.permission.PRIVACY_WINDOW, which needs to be declared in module.json5
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| visualEffect | string | none | No | Visual effect during screenshot or screen recording. Only the values none and hidden are supported. If hidden is passed, the screen is hidden during screenshot or screen recording. |
| success | function | - | No | Callback triggered when the API call is successful. |
| fail | function | - | No | Callback triggered when the API call fails. |
| complete | function | - | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
|---|---|
| 12005001 | setVisualEffectOnCapture exception. |
Example:
has.setVisualEffectOnCapture({
visualEffect: 'hidden',
success: () => {
console.info('setVisualEffectOnCapture success.');
},
fail: (err) => {
console.error('setVisualEffectOnCapture fail:', err);
},
complete: (res) => {
console.info('setVisualEffectOnCapture complete.', res);
}
}); has.setScreenBrightness (Object object)
Sets screen brightness. The setting is effective only for the current atomic service.
Since: 1.0.4
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| value | number | Yes | Screen brightness. The value ranges from 0 to 1, where 0 indicates darkest and 1 indicates brightest. The value -1 indicates that the screen brightness changes with the system. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
|---|---|
| 102 | The value is out of range. |
| 12001301 | 1. setScreenBrightness error. 2. setScreenBrightness exception. For details, see Window Error Codes. |
Example:
has.setScreenBrightness({
value: 0.5,
success:() => {
console.info('setScreenBrightness success');
},
fail: (err) => {
console.error('setScreenBrightness fail', err)
},
complete: (res) => {
console.info('setScreenBrightness complete', res);
}
}); has.setKeepScreenOn (Object object)
Sets whether to keep the screen steady on. The setting is effective only for the current atomic service.
Since: 1.0.4
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| keepScreenOn | boolean | Yes | Whether to keep the screen steady on. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
|---|---|
| 101 | Context is null or undefined. |
| 12001401 | setKeepScreenOn exception. For details, see Window Error Codes. |
Example:
has.setKeepScreenOn({
keepScreenOn: true,
success: () => {
console.info('setKeepScreenOn success');
},
fail: (err) => {
console.error('setKeepScreenOn fail', err);
},
complete: (res) => {
console.info('setKeepScreenOn complete', res);
}
}); has.onUserCaptureScreen (function callback)
Enables listening for proactive screenshot events. Such an event is triggered when a user takes a screenshot by pressing the system screenshot button. Only one listener can be registered.
Since: 1.0.4
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| callback | function | Yes | Callback for the proactive screenshot event. |
Error code information
| Error Code | Error Message |
|---|---|
| 101 | Context is null or undefined. |
Example:
has.onUserCaptureScreen(function() {
console.info('Listen for user screenshot events');
}); has.offUserCaptureScreen (function callback)
Cancels listening for proactive screenshot events.
Since: 1.0.4
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| callback | function | No | Callback for the proactive screenshot event. |
Error code information
| Error Code | Error Message |
|---|---|
| 101 | Context is null or undefined. |
Example:
const fun = () => {
console.info('screenshotCallback');
};
has.onUserCaptureScreen(fun);
has.offUserCaptureScreen(fun); has. getScreenBrightness (Object object)
Obtains the current screen brightness of the atomic service.
Since: 1.0.4
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Return value of success
| Attribute | Type | Description |
|---|---|---|
| value | number | Screen brightness. The value ranges from 0 to 1, where 0 indicates darkest and 1 indicates brightest. The value -1 indicates that the screen brightness changes with the system. |
Error code information
| Error Code | Error Message |
|---|---|
| 101 | Context is null or undefined. |
| 12001201 | getScreenBrightness error. For details, see Window Error Codes. |
Example:
has.getScreenBrightness({
success: (res) => {
console.info('getScreenBrightness success', res);
},
fail: (err) => {
console.error('getScreenBrightness fail', err);
},
complete: (res) => {
console.info('getScreenBrightness complete', res);
}
});