未验证 提交 ec2160c6 编写于 作者: O openharmony_ci 提交者: Gitee

!1715 modify settings api

Merge pull request !1715 from 吕晓强/settings_modify
...@@ -19,9 +19,9 @@ import settings from '@ohos.settings'; ...@@ -19,9 +19,9 @@ import settings from '@ohos.settings';
None None
## settings.getUri ## settings.getUriSync
getUri(name: string): string getUriSync(name: string): string
Obtains the URI of a data item. Obtains the URI of a data item.
...@@ -38,13 +38,13 @@ Obtains the URI of a data item. ...@@ -38,13 +38,13 @@ Obtains the URI of a data item.
- Example - Example
``` ```
// Obtain the URI of a data item. // Obtain the URI of a data item.
let urivar = settings.getUri('settings.screen.brightness'); let urivar = settings.getUriSync('settings.screen.brightness');
``` ```
## settings.getValue ## settings.getValueSync
getValue(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string getValueSync(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string
Obtains the value of a data item. Obtains the value of a data item.
...@@ -66,18 +66,18 @@ Obtains the value of a data item. ...@@ -66,18 +66,18 @@ Obtains the value of a data item.
// Obtain the value of 'settings.screen.brightness' (this data item already exists in the database). // Obtain the value of 'settings.screen.brightness' (this data item already exists in the database).
let brightness = 'settings.screen.brightness'; let brightness = 'settings.screen.brightness';
let uri = settings.getUri(brightness); let uri = settings.getUriSync(brightness);
let helper = featureAbility.acquireDataAbilityHelper(uri); let helper = featureAbility.acquireDataAbilityHelper(uri);
let value = settings.getValue(helper, brightness, '10'); let value = settings.getValueSync(helper, brightness, '10');
``` ```
## settings.setValue ## settings.setValueSync
setValue(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean setValueSync(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean
Sets the value of a data item. Sets the value of a data item.
If the specified data item exists in the database, the **setValue** method updates the value of the data item. If the data item does not exist in the database, the **setValue** method inserts the data item into the database. 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.
To use this method, you must have the **ohos.permission.WRITE_SYSTEM_SETTING** permission. To use this method, you must have the **ohos.permission.WRITE_SYSTEM_SETTING** permission.
...@@ -97,10 +97,10 @@ To use this method, you must have the **ohos.permission.WRITE_SYSTEM_SETTING** p ...@@ -97,10 +97,10 @@ To use this method, you must have the **ohos.permission.WRITE_SYSTEM_SETTING** p
``` ```
import featureAbility from '@ohos.featureAbility'; import featureAbility from '@ohos.featureAbility';
// Update the value of 'settings.screen.brightness'. (As this data item exists in the database, the setValue method // Update the value of 'settings.screen.brightness'. (As this data item exists in the database, the setValueSync method
will update the value of the data item.) will update the value of the data item.)
let brightness = 'settings.screen.brightness'; let brightness = 'settings.screen.brightness';
let uri = settings.getUri(brightness); let uri = settings.getUriSync(brightness);
let helper = featureAbility.acquireDataAbilityHelper(uri); let helper = featureAbility.acquireDataAbilityHelper(uri);
let ret = settings.setValue(helper, brightness, '100'); let ret = settings.setValueSync(helper, brightness, '100');
``` ```
...@@ -19,9 +19,9 @@ import settings from '@ohos.settings'; ...@@ -19,9 +19,9 @@ import settings from '@ohos.settings';
## settings.getUri ## settings.getUriSync
getUri(name: string): string getUriSync(name: string): string
获取数据项的URI。 获取数据项的URI。
...@@ -38,13 +38,13 @@ getUri(name: string): string ...@@ -38,13 +38,13 @@ getUri(name: string): string
- 示例: - 示例:
``` ```
// 获取数据项的URI // 获取数据项的URI
let urivar = settings.getUri('settings.screen.brightness'); let urivar = settings.getUriSync('settings.screen.brightness');
``` ```
## settings.getValue ## settings.getValueSync
getValue(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string getValueSync(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string
获取数据项的值。 获取数据项的值。
...@@ -66,18 +66,18 @@ getValue(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): ...@@ -66,18 +66,18 @@ getValue(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string):
//获取数据项亮度的值(该数据项在数据库中已存在) //获取数据项亮度的值(该数据项在数据库中已存在)
let brightness = 'settings.screen.brightness'; let brightness = 'settings.screen.brightness';
let uri = settings.getUri(brightness); let uri = settings.getUriSync(brightness);
let helper = featureAbility.acquireDataAbilityHelper(uri); let helper = featureAbility.acquireDataAbilityHelper(uri);
let value = settings.getValue(helper, brightness, '10'); let value = settings.getValueSync(helper, brightness, '10');
``` ```
## settings.setValue ## settings.setValueSync
setValue(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean setValueSync(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean
设置数据项的值。 设置数据项的值。
如果数据库中已经存在该数据项,则setValue方法将更新该数据项的值;如果数据库中尚未存在该数据项,则setValue方法将向数据库中插入该数据项。 如果数据库中已经存在该数据项,则setValueSync方法将更新该数据项的值;如果数据库中尚未存在该数据项,则setValueSync方法将向数据库中插入该数据项。
使用此方法需获取ohos.permission.WRITE_SYSTEM_SETTING权限。 使用此方法需获取ohos.permission.WRITE_SYSTEM_SETTING权限。
...@@ -97,9 +97,9 @@ setValue(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boo ...@@ -97,9 +97,9 @@ setValue(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boo
``` ```
import featureAbility from '@ohos.featureAbility'; import featureAbility from '@ohos.featureAbility';
//更新数据项亮度的值(该数据项在数据库中已存在,故setValue方法将更新该数据项的值) //更新数据项亮度的值(该数据项在数据库中已存在,故setValueSync方法将更新该数据项的值)
let brightness = 'settings.screen.brightness'; let brightness = 'settings.screen.brightness';
let uri = settings.getUri(brightness); let uri = settings.getUriSync(brightness);
let helper = featureAbility.acquireDataAbilityHelper(uri); let helper = featureAbility.acquireDataAbilityHelper(uri);
let ret = settings.setValue(helper, brightness, '100'); let ret = settings.setValueSync(helper, brightness, '100');
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册