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 d9dec4275b860bf3be3c81d6eb3fc29131ead9d9..49f7d8163bad10bad37ce1e6fdbb085d948da5cb 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-settings.md +++ b/zh-cn/application-dev/reference/apis/js-apis-settings.md @@ -8,7 +8,7 @@ ## 导入模块 -```ts +```js import settings from '@ohos.settings'; ``` @@ -203,9 +203,9 @@ getURI(name: string, callback: AsyncCallback\): void **示例**: ```js - settings.getUri(settings.display.SCREEN_BRIGHTNESS_STATUS, (uri) => { - console.log(`callback:uri -> ${JSON.stringify(uri)}`) - }) +settings.getURI(settings.display.SCREEN_BRIGHTNESS_STATUS, (uri) => { + console.log(`callback:uri -> ${JSON.stringify(uri)}`) +}) ``` ## setting.getURI @@ -231,9 +231,9 @@ getURI(name: string): Promise\ **示例**: ```js - settings.getUri(settings.display.SCREEN_BRIGHTNESS_STATUS).then((uri) => { - console.log(`promise:uri -> ${JSON.stringify(uri)}`) - }) +settings.getURI(settings.display.SCREEN_BRIGHTNESS_STATUS).then((uri) => { + console.log(`promise:uri -> ${JSON.stringify(uri)}`) +}) ``` ## setting.getValue @@ -255,15 +255,17 @@ getValue(dataAbilityHelper: DataAbilityHelper, name: string, callback: AsyncCall **示例**: ```js - let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); - let helper = featureAbility.acquireDataAbilityHelper(uri); - settings.getValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, (err, value) => { - if (err) { - console.error(`Failed to get the setting. ${err.message} `); - return; - } - console.log(`callback:value -> ${JOSN.stringify(value)}`) - }); +import featureAbility from '@ohos.ability.featureAbility'; + +let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); +let helper = featureAbility.acquireDataAbilityHelper(uri); +settings.getValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, (err, value) => { + if (err) { + console.error(`Failed to get the setting. ${err.message} `); + return; + } + console.log(`callback:value -> ${JSON.stringify(value)}`) +}); ``` ## setting.getValue @@ -290,11 +292,13 @@ getValue(dataAbilityHelper: DataAbilityHelper, name: string): Promise\ **示例**: ```js - let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); - let helper = featureAbility.acquireDataAbilityHelper(uri); - settings.getValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS).then((value) => { - console.log(`promise:value -> ${JOSN.stringify(value)}`) - }); +import featureAbility from '@ohos.ability.featureAbility'; + +let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); +let helper = featureAbility.acquireDataAbilityHelper(uri); +settings.getValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS).then((value) => { + console.log(`promise:value -> ${JSON.stringify(value)}`) +}); ``` ## settings.setValue @@ -319,14 +323,14 @@ setValue(dataAbilityHelper: DataAbilityHelper, name: string, value: object, call **示例**: ```js - import featureAbility from '@ohos.ability.featureAbility'; - - //更新数据项亮度的值(该数据项在数据库中已存在,故setValue方法将更新该数据项的值) - let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); - let helper = featureAbility.acquireDataAbilityHelper(uri); - settings.setValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100', (status) => { - console.log('Callback return whether value is set.'); - }); +import featureAbility from '@ohos.ability.featureAbility'; + +//更新数据项亮度的值(该数据项在数据库中已存在,故setValue方法将更新该数据项的值) +let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); +let helper = featureAbility.acquireDataAbilityHelper(uri); +settings.setValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100', (status) => { + console.log('Callback return whether value is set.'); +}); ``` ## settings.setValue @@ -356,14 +360,14 @@ setValue(dataAbilityHelper: DataAbilityHelper, name: string, value: object): Pro **示例**: ```js - import featureAbility from '@ohos.ability.featureAbility'; - - //更新数据项亮度的值(该数据项在数据库中已存在,故setValue方法将更新该数据项的值) - let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); - let helper = featureAbility.acquireDataAbilityHelper(uri); - settings.setValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100').then((status) => { - console.log('Callback return whether value is set.'); - }); +import featureAbility from '@ohos.ability.featureAbility'; + +//更新数据项亮度的值(该数据项在数据库中已存在,故setValue方法将更新该数据项的值) +let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); +let helper = featureAbility.acquireDataAbilityHelper(uri); +settings.setValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100').then((status) => { + console.log('Callback return whether value is set.'); +}); ``` ## settings.enableAirplaneMode @@ -384,14 +388,14 @@ enableAirplaneMode(enable: boolean, callback: AsyncCallback\): void **示例**: ```js - isEnabled =true; - enableAirplaneMode(isEnabled, (err) => { - if(err) { - console.log('Failed to enable AirplaneMode.'); - return; - } - console.log('Return true if enable.'); - }) +let isEnabled = true; +settings.enableAirplaneMode(isEnabled, (err) => { + if (err) { + console.log('Failed to enable AirplaneMode.'); + return; + } + console.log('Return true if enable.'); +}) ``` ## settings.enableAirplaneMode @@ -417,14 +421,14 @@ enableAirplaneMode(enable: boolean): Promise\ **示例**: ```js - isEnabled =true; - enableAirplaneMode(isEnabled).then((err) => { - if(err) { - console.log('Failed to enable AirplaneMode.'); - return; - } - console.log('Return true if enable.'); - }); +let isEnabled = true; +settingsenableAirplaneMode(isEnabled).then((err) => { + if (err) { + console.log('Failed to enable AirplaneMode.'); + return; + } + console.log('Return true if enable.'); +}); ``` ## settings.canShowFloating @@ -444,9 +448,9 @@ canShowFloating(callback: AsyncCallback\): void **示例**: ```js - canShowFloating((status) => { - console.log('Checks whether a specified application can show as float window.'); - }); +settings.canShowFloating((status) => { + console.log('Checks whether a specified application can show as float window.'); +}); ``` ## settings.canShowFloating @@ -466,9 +470,9 @@ canShowFloating(): Promise\ **示例**: ```js - canShowFloating().then((status) => { - console.log('Checks whether a specified application can show as float window.'); - }); +settings.canShowFloating().then((status) => { + console.log('Checks whether a specified application can show as float window.'); +}); ``` ## settings.getUriSync8+ @@ -494,8 +498,8 @@ getUriSync(name: string): string **示例**: ```js - // 获取数据项的URI - let urivar = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); +// 获取数据项的URI +let urivar = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); ``` ## settings.getValueSync8+ @@ -523,12 +527,12 @@ getValueSync(dataAbilityHelper: DataAbilityHelper, name: string, defValue: strin **示例**: ```js - import featureAbility from '@ohos.ability.featureAbility'; +import featureAbility from '@ohos.ability.featureAbility'; - //获取数据项亮度的值(该数据项在数据库中已存在) - let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); - let helper = featureAbility.acquireDataAbilityHelper(uri); - let value = settings.getValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '10'); +//获取数据项亮度的值(该数据项在数据库中已存在) +let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); +let helper = featureAbility.acquireDataAbilityHelper(uri); +let value = settings.getValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '10'); ``` ## settings.setValueSync8+ @@ -560,10 +564,10 @@ setValueSync(dataAbilityHelper: DataAbilityHelper, name: string, value: string): **示例**: ```js - import featureAbility from '@ohos.ability.featureAbility'; +import featureAbility from '@ohos.ability.featureAbility'; - //更新数据项亮度的值(该数据项在数据库中已存在,故setValueSync方法将更新该数据项的值) - let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); - let helper = featureAbility.acquireDataAbilityHelper(uri); - let ret = settings.setValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100'); +//更新数据项亮度的值(该数据项在数据库中已存在,故setValueSync方法将更新该数据项的值) +let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); +let helper = featureAbility.acquireDataAbilityHelper(uri); +let ret = settings.setValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100'); ```