diff --git a/en/application-dev/reference/apis/js-apis-settings.md b/en/application-dev/reference/apis/js-apis-settings.md index 83b3ac3920ac5fe6bca78974f664174157da86b0..81444a400e5dc33c2a2b53c489488fea4fe1be58 100644 --- a/en/application-dev/reference/apis/js-apis-settings.md +++ b/en/application-dev/reference/apis/js-apis-settings.md @@ -27,7 +27,7 @@ Obtains the URI of a data item. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| name | string | Yes| Name of the target data item. Data items can be classified as follows:
| +| name | string | Yes| Name of the target data item. Data items can be classified as follows:
| **Return value** @@ -39,7 +39,7 @@ Obtains the URI of a data item. ```typescript // Obtain the URI of a data item. - let urivar = settings.getUriSync('settings.screen.brightness'); + let urivar = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); ``` @@ -55,7 +55,7 @@ Obtains the value of a data item. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | dataAbilityHelper | [DataAbilityHelper](js-apis-dataAbilityHelper.md) | Yes| **DataAbilityHelper** class.| -| name | string | Yes| Name of the target data item. Data items can be classified as follows:
| +| name | string | Yes| Name of the target data item. Data items can be classified as follows:
| | defValue | string | Yes| Default value This parameter is user-defined. If it is not found in the database, the default value is returned.| **Return value** @@ -69,11 +69,10 @@ Obtains the value of a data item. ```typescript import featureAbility from '@ohos.ability.featureAbility'; -// Obtain the value of 'settings.screen.brightness' (this data item already exists in the database). -let brightness = 'settings.screen.brightness'; -let uri = settings.getUriSync(brightness); +// Obtain the value of settings.display.SCREEN_BRIGHTNESS_STATUS (this data item already exists in the database). +let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); let helper = featureAbility.acquireDataAbilityHelper(uri); -let value = settings.getValueSync(helper, brightness, '10'); +let value = settings.getValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '10'); ``` @@ -85,7 +84,7 @@ Sets the value of a data item. If the specified data item exists in the database, the **setValueSync** method updates the value of the data item. If the data item does not exist in the database, the **setValueSync** method inserts the data item into the database. -**Required permissions**: ohos.permission.WRITE_SYSTEM_SETTING +**Required permissions**: ohos.permission.MODIFY_SETTINGS **System capability**: SystemCapability.Applictaions.settings.Core @@ -94,7 +93,7 @@ If the specified data item exists in the database, the **setValueSync** method u | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | dataAbilityHelper | [DataAbilityHelper](js-apis-dataAbilityHelper.md) | Yes| **DataAbilityHelper** class.| -| name | string | Yes| Name of the target data item. Data items can be classified as follows:
| +| name | string | Yes| Name of the target data item. Data items can be classified as follows:
| | value | string | Yes| Value of the data item.| **Return value** @@ -108,10 +107,9 @@ If the specified data item exists in the database, the **setValueSync** method u ```typescript import featureAbility from '@ohos.ability.featureAbility'; -// Update the value of 'settings.screen.brightness'. (As this data item exists in the database, the setValueSync +// Update the value of settings.display.SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the setValueSync method will update the value of the data item.) -let brightness = 'settings.screen.brightness'; -let uri = settings.getUriSync(brightness); +let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); let helper = featureAbility.acquireDataAbilityHelper(uri); -let ret = settings.setValueSync(helper, brightness, '100'); +let ret = settings.setValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100'); ``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-settings.md b/zh-cn/application-dev/reference/apis/js-apis-settings.md index 0feab0dff0c31e84b0eee5569685b2d7d0f280f8..e4b3595f061e8a549450f81fde6fd36ed5578809 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-settings.md +++ b/zh-cn/application-dev/reference/apis/js-apis-settings.md @@ -26,7 +26,7 @@ getUriSync(name: string): string - 参数: | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | - | name | string | 是 | 数据项的名称。数据项名称分为以下两种:
| + | name | string | 是 | 数据项的名称。数据项名称分为以下两种:
| - 返回值: | 类型 | 说明 | @@ -36,7 +36,7 @@ getUriSync(name: string): string - 示例: ```typescript // 获取数据项的URI - let urivar = settings.getUriSync('settings.screen.brightness'); + let urivar = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); ``` @@ -52,7 +52,7 @@ getValueSync(dataAbilityHelper: DataAbilityHelper, name: string, defValue: strin | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | dataAbilityHelper | [DataAbilityHelper](js-apis-dataAbilityHelper.md) | 是 | 数据管理辅助类。 | - | name | string | 是 | 数据项的名称。数据项名称分为以下两种:
| + | name | string | 是 | 数据项的名称。数据项名称分为以下两种:
| | defValue | string | 是 | 默认值。由开发者设置,当未从数据库中查询到该数据时,则返回该默认值。 | - 返回值: @@ -65,10 +65,9 @@ getValueSync(dataAbilityHelper: DataAbilityHelper, name: string, defValue: strin import featureAbility from '@ohos.ability.featureAbility'; //获取数据项亮度的值(该数据项在数据库中已存在) - let brightness = 'settings.screen.brightness'; - let uri = settings.getUriSync(brightness); + let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); let helper = featureAbility.acquireDataAbilityHelper(uri); - let value = settings.getValueSync(helper, brightness, '10'); + let value = settings.getValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '10'); ``` @@ -79,7 +78,7 @@ setValueSync(dataAbilityHelper: DataAbilityHelper, name: string, value: string): 设置数据项的值。 如果数据库中已经存在该数据项,则setValueSync方法将更新该数据项的值;如果数据库中尚未存在该数据项,则setValueSync方法将向数据库中插入该数据项。 -**需要权限**:ohos.permission.WRITE_SYSTEM_SETTING。 +**需要权限**:ohos.permission.MODIFY_SETTINGS。 **系统能力**:SystemCapability.Applictaions.settings.Core。 @@ -87,7 +86,7 @@ setValueSync(dataAbilityHelper: DataAbilityHelper, name: string, value: string): | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | dataAbilityHelper | [DataAbilityHelper](js-apis-dataAbilityHelper.md) | 是 | 数据管理辅助类。 | - | name | string | 是 | 数据项的名称。数据项名称分为以下两种:
| + | name | string | 是 | 数据项的名称。数据项名称分为以下两种:
| | value | string | 是 | 数据项的具体数值。 | - 返回值: @@ -100,8 +99,7 @@ setValueSync(dataAbilityHelper: DataAbilityHelper, name: string, value: string): import featureAbility from '@ohos.ability.featureAbility'; //更新数据项亮度的值(该数据项在数据库中已存在,故setValueSync方法将更新该数据项的值) - let brightness = 'settings.screen.brightness'; - let uri = settings.getUriSync(brightness); + let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); let helper = featureAbility.acquireDataAbilityHelper(uri); - let ret = settings.setValueSync(helper, brightness, '100'); + let ret = settings.setValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100'); ```