diff --git a/zh-cn/application-dev/device/stationary-guidelines.md b/zh-cn/application-dev/device/stationary-guidelines.md index 2cce3c90983779331f1e4ae27ac7a5bdb64b3dfa..190881fe356452c6c3cadb14b8aecbb6efe4fbd8 100644 --- a/zh-cn/application-dev/device/stationary-guidelines.md +++ b/zh-cn/application-dev/device/stationary-guidelines.md @@ -45,40 +45,43 @@ 1. 订阅绝对静止的进入事件,1秒上报一次。 - ```js + ```ts import stationary from '@ohos.stationary'; - var reportLatencyNs = 1000000000; + let reportLatencyNs = 1000000000; try { stationary.on('still', stationary.ActivityEvent.ENTER, reportLatencyNs, (data) => { console.log('data='+ JSON.stringify(data)); }) - } catch (err) { - console.error('errCode: ' + err.code + ' ,msg: ' + err.message); + } catch (error) { + let message = (error as BusinessError).message; + console.error('stationary on failed:' + message); } ``` 2. 查询绝对静止状态的进入事件。 - ```js + ```ts import stationary from '@ohos.stationary'; try { stationary.once('still', (data) => { console.log('data='+ JSON.stringify(data)); }) - } catch (err) { - console.error('errCode: ' + err.code + ' ,msg: ' + err.message); + } catch (error) { + let message = (error as BusinessError).message; + console.error('stationary once failed:' + message); } ``` 3. 取消订阅绝对静止状态的进入事件。 - ```js + ```ts import stationary from '@ohos.stationary'; try { stationary.off('still', stationary.ActivityEvent.ENTER, (data) => { console.log('data='+ JSON.stringify(data)); }) - } catch (err) { - console.error('errCode: ' + err.code + ' ,msg: ' + err.message); + } catch (error) { + let message = (error as BusinessError).message; + console.error('stationary off failed:' + message); } ```