1# @ohos.brightness (屏幕亮度)(系统接口) 2 3<!--Kit: Basic Services Kit--> 4<!--Subsystem: PowerManager--> 5<!--Owner: @zhang-yinglie; @volcano_wang--> 6<!--Designer: @wangyantian0--> 7<!--Tester: @alien0208--> 8<!--Adviser: @w_Machine_cc--> 9 10该模块提供屏幕亮度的设置接口。 11 12> **说明:** 13> 14> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 15> 16> - 本模块接口为系统接口。 17 18## 导入模块 19 20```js 21import {brightness} from '@kit.BasicServicesKit'; 22``` 23 24## brightness.setValue 25 26setValue(value: number): void 27 28设置系统的屏幕亮度。 29 30**系统接口:** 此接口为系统接口。 31 32**系统能力:** SystemCapability.PowerManager.DisplayPowerManager 33 34**参数:** 35 36| 参数名 | 类型 | 必填 | 说明 | 37| ------ | ------ | ---- | ----------------------- | 38| value | number | 是 | 亮度的值。范围:0~255;该参数必须为数字类型。 | 39 40**错误码:** 41 42以下错误码的详细介绍请参见[屏幕亮度错误码](errorcode-brightness.md)和[通用错误码](../errorcode-universal.md)。 43 44| 错误码ID | 错误信息 | 45|---------|---------| 46| 4700101 | Failed to connect to the service. | 47| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 48| 202 | Permission verification failed. A non-system application calls a system API. | 49 50**示例:** 51 52```js 53try { 54 brightness.setValue(128); 55} catch(err) { 56 console.error('set brightness failed, err: ' + err); 57} 58``` 59 60## brightness.setValue<sup>11+</sup> 61 62setValue(value: number, continuous: boolean): void 63 64设置系统的屏幕亮度。用于连续调节亮度的场景,在连续调节亮度过程中,设置continuous为true,结束时设置continuous为false,会有更好的性能。 65 66**系统接口:** 此接口为系统接口。 67 68**系统能力:** SystemCapability.PowerManager.DisplayPowerManager 69 70**参数:** 71 72| 参数名 | 类型 | 必填 | 说明 | 73| ------ | ------ | ---- | ----------------------- | 74| value | number | 是 | 亮度的值。范围:0~255。 | 75| continuous | boolean | 是 | 亮度调节是否连续。true表示亮度调节连续,false表示亮度调节不连续,默认为false。 | 76 77**错误码:** 78 79以下错误码的详细介绍请参见[屏幕亮度错误码](errorcode-brightness.md)和[通用错误码](../errorcode-universal.md)。 80 81| 错误码ID | 错误信息 | 82|---------|---------| 83| 4700101 | Failed to connect to the service. | 84| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 85| 202 | Permission verification failed. A non-system application calls a system API. | 86 87**示例:** 88 89```js 90try { 91 brightness.setValue(128, true); 92} catch(err) { 93 console.error('set brightness failed, err: ' + err); 94} 95```