Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
447fd830
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
447fd830
编写于
3月 14, 2022
作者:
O
openharmony_ci
提交者:
Gitee
3月 14, 2022
浏览文件
操作
浏览文件
下载
差异文件
!1995 修改sensor的on、once、off用例
Merge pull request !1995 from 陈飞飞/master
上级
3f7a075b
b2854eb6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
739 addition
and
348 deletion
+739
-348
zh-cn/application-dev/reference/apis/js-apis-sensor.md
zh-cn/application-dev/reference/apis/js-apis-sensor.md
+739
-348
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-sensor.md
浏览文件 @
447fd830
...
...
@@ -11,9 +11,9 @@ import sensor from '@ohos.sensor';
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_ACCELEROMETER)
## sensor.on(SensorType.SENSOR_TYPE_ID_ACCELEROMETER)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Async
Callback
<
AccelerometerResponse
>
,options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback:
Callback
<
AccelerometerResponse
>
,options?: Options): void
监听加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -26,16 +26,12 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallbac
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。 |
| callback |
Async
Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
| 是 | 注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
| callback | Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
| 是 | 注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -45,9 +41,9 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallbac
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION)
## sensor.on(SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Async
Callback
<
LinearAccelerometerResponse
>
, options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:
Callback
<
LinearAccelerometerResponse
>
, options?: Options): void
监听线性加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -59,16 +55,12 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCallb
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 |
| callback |
Async
Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 | 注册线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
| callback | Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 | 注册线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,function(data){
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -78,9 +70,9 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCallb
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED)
## sensor.on(SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:Async
Callback
<
AccelerometerUncalibratedResponse
>
, options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:
Callback
<
AccelerometerUncalibratedResponse
>
, options?: Options): void
监听未校准加速度计传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -92,16 +84,12 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:Asy
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的未校准加速度计传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
| callback |
Async
Callback
<
[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)
>
| 是 | 注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
| callback | Callback
<
[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)
>
| 是 | 注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -114,9 +102,9 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:Asy
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_GRAVITY)
## sensor.on(SensorType.SENSOR_TYPE_ID_GRAVITY)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Async
Callback
<
GravityResponse
>
,options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_GRAVITY, callback:
Callback
<
GravityResponse
>
,options?: Options): void
监听重力传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -126,16 +114,12 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback<Gr
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的重力传感器类型为SENSOR_TYPE_ID_GRAVITY。 |
| callback |
Async
Callback
<
[GravityResponse](#gravityresponse)
>
| 是 | 注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |
| callback | Callback
<
[GravityResponse](#gravityresponse)
>
| 是 | 注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(data){
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -145,9 +129,9 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback<Gr
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_GYROSCOPE)
## sensor.on(SensorType.SENSOR_TYPE_ID_GYROSCOPE)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Async
Callback
<
GyroscopeResponse
>
, options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback:
Callback
<
GyroscopeResponse
>
, options?: Options): void
监听陀螺仪传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -159,16 +143,12 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback<
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。 |
| callback |
Async
Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 | 注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
| callback | Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 | 注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(data){
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -178,9 +158,9 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback<
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED)
## sensor.on(SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Async
Callback
<
GyroscopeUncalibratedResponse
>
, options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:
Callback
<
GyroscopeUncalibratedResponse
>
, options?: Options): void
监听未校准陀螺仪传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -192,16 +172,12 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:AsyncCa
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback |
Async
Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 | 注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
| callback | Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 | 注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(data){
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -214,9 +190,9 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:AsyncCa
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION)
## sensor.on(SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Async
Callback
<
SignificantMotionResponse
>
, options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback:
Callback
<
SignificantMotionResponse
>
, options?: Options): void
监听大幅动作传感器数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -226,16 +202,12 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: AsyncCal
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的大幅动作传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
| callback |
Async
Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 | 注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
| callback | Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 | 注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(data){
console.info('Scalar data: ' + data.scalar);
},
{interval: 10000000}
...
...
@@ -243,9 +215,9 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: AsyncCal
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION)
## sensor.on(SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Async
Callback
<
PedometerDetectionResponse
>
, options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback:
Callback
<
PedometerDetectionResponse
>
, options?: Options): void
监听计步检测传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -257,16 +229,12 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: AsyncCa
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
| callback |
Async
Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 | 注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
| callback | Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 | 注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(data){
console.info('Scalar data: ' + data.scalar);
},
{interval: 10000000}
...
...
@@ -274,9 +242,9 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: AsyncCa
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_PEDOMETER)
## sensor.on(SensorType.SENSOR_TYPE_ID_PEDOMETER)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Async
Callback
<
PedometerResponse
>
, options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_PEDOMETER, callback:
Callback
<
PedometerResponse
>
, options?: Options): void
监听计步传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -288,16 +256,12 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback<
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。 |
| callback |
Async
Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 | 注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
| callback | Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 | 注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(data){
console.info('Steps: ' + data.steps);
},
{interval: 10000000}
...
...
@@ -305,9 +269,9 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback<
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE)
## sensor.on(SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Async
Callback
<
AmbientTemperatureResponse
>
, options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:
Callback
<
AmbientTemperatureResponse
>
, options?: Options): void
监听环境温度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -317,16 +281,12 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCallb
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
| callback |
Async
Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 | 注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
| callback | Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 | 注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(data){
console.info('Temperature: ' + data.temperature);
},
{interval: 10000000}
...
...
@@ -334,9 +294,9 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCallb
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD)
## sensor.on(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Async
Callback
<
MagneticFieldResponse
>
,options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback:
Callback
<
MagneticFieldResponse
>
,options?: Options): void
监听磁场传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -346,16 +306,12 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallbac
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。 |
| callback |
Async
Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 | 注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
| callback | Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 | 注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(data){
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -365,9 +321,9 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallbac
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED)
## sensor.on(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:Async
Callback
<
MagneticFieldUncalibratedResponse
>
, options: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:
Callback
<
MagneticFieldUncalibratedResponse
>
, options: Options): void
监听未校准磁场传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -377,16 +333,12 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:As
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
| callback |
Async
Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 | 注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
| callback | Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 | 注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(data){
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -399,9 +351,9 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:As
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_PROXIMITY)
## sensor.on(SensorType.SENSOR_TYPE_ID_PROXIMITY)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Async
Callback
<
ProximityResponse
>
,options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_PROXIMITY, callback:
Callback
<
ProximityResponse
>
,options?: Options): void
监听接近光传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -411,16 +363,12 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback<P
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。 |
| callback |
Async
Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 | 注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
| callback | Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 | 注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){
console.info('Distance: ' + data.distance);
},
{interval: 10000000}
...
...
@@ -428,9 +376,9 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback<P
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_HUMIDITY)
## sensor.on(SensorType.SENSOR_TYPE_ID_HUMIDITY)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Async
Callback
<
HumidityResponse
>
,options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_HUMIDITY, callback:
Callback
<
HumidityResponse
>
,options?: Options): void
监听湿度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -440,16 +388,12 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback<H
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。 |
| callback |
Async
Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 | 注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
| callback | Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 | 注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(data){
console.info('Humidity: ' + data.humidity);
},
{interval: 10000000}
...
...
@@ -457,9 +401,9 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback<H
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_BAROMETER)
## sensor.on(SensorType.SENSOR_TYPE_ID_BAROMETER)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Async
Callback
<
BarometerResponse
>
,options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_BAROMETER, callback:
Callback
<
BarometerResponse
>
,options?: Options): void
监听气压计传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -469,16 +413,12 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback<B
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。 |
| callback |
Async
Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 | 注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
| callback | Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 | 注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(data){
console.info('Atmospheric pressure: ' + data.pressure);
},
{interval: 10000000}
...
...
@@ -486,9 +426,9 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback<B
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_HALL)
## sensor.on(SensorType.SENSOR_TYPE_ID_HALL)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_HALL, callback: Async
Callback
<
HallResponse
>
, options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_HALL, callback:
Callback
<
HallResponse
>
, options?: Options): void
监听霍尔传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -498,16 +438,12 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_HALL, callback: AsyncCallback<HallR
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的霍尔传感器类型为SENSOR_TYPE_ID_HALL。 |
| callback |
Async
Callback
<
[HallResponse](#hallresponse)
>
| 是 | 注册霍尔传感器的回调函数,上报的数据类型为
HallResponse。 |
| callback | Callback
<
[HallResponse](#hallresponse)
>
| 是 | 注册霍尔传感器的回调函数,上报的数据类型为
HallResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){
console.info('Status: ' + data.status);
},
{interval: 10000000}
...
...
@@ -515,9 +451,9 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_HALL, callback: AsyncCallback<HallR
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT)
## sensor.on(SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Async
Callback
<
LightResponse
>
, options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback:
Callback
<
LightResponse
>
, options?: Options): void
监听环境光传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -527,16 +463,12 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallback&
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 |
| callback |
Async
Callback
<
[LightResponse](#lightresponse)
>
| 是 | 注册环境光传感器的回调函数,上报的数据类型为LightResponse。 |
| callback | Callback
<
[LightResponse](#lightresponse)
>
| 是 | 注册环境光传感器的回调函数,上报的数据类型为LightResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(data){
console.info(' Illumination: ' + data.intensity);
},
{interval: 10000000}
...
...
@@ -544,9 +476,9 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallback&
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_ORIENTATION)
## sensor.on(SensorType.SENSOR_TYPE_ID_ORIENTATION)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Async
Callback
<
OrientationResponse
>
, options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_ORIENTATION, callback:
Callback
<
OrientationResponse
>
, options?: Options): void
监听方向传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -556,28 +488,50 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: AsyncCallback&l
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的方向传感器类型为SENSOR_TYPE_ID_ORIENTATION |
| callback |
Async
Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 | 注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
| callback | Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 | 注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(data){
console.info('The device rotates at an angle around the X axis: ' + data.beta);
console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
},
{interval: 10000000}
);
```
## sensor.on(SensorType.SENSOR_TYPE_ID_HEART_RATE)
on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback
<
HeartRateResponse
>
, options?: Options): void
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR)
监听心率传感器数据变化一次。
**需要权限**
:ohos.permission.READ_HEALTH_DATA
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
on(type:sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback:AsyncCallback
<
RotationVectorResponse
>
,options?: Options): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的心率传感器类型为SENSOR_TYPE_ID_HEART_RATE。 |
| callback | Callback
<
[HeartRateResponse](#heartrateresponse)
>
| 是 | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE,function(data){
console.info("Heart rate: " + data.heartRate);
},
{interval: 10000000}
);
```
## sensor.on(SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR)
on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback
<
RotationVectorResponse
>
,options?: Options): void
监听旋转矢量传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -587,28 +541,25 @@ on(type:sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback:AsyncCallback&
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
| callback |
Async
Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 | 注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
| callback | Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 | 注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(data){
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
console.info('Scalar quantity: ' + data.w);
},
{interval: 10000000}
);
```
## sensor.on(
sensor.
SensorType.SENSOR_TYPE_ID_WEAR_DETECTION)
## sensor.on(SensorType.SENSOR_TYPE_ID_WEAR_DETECTION)
on(type:
sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Async
Callback
<
WearDetectionResponse
>
,options?: Options): void
on(type:
SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback:
Callback
<
WearDetectionResponse
>
,options?: Options): void
监听佩戴检测传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
...
...
@@ -618,16 +569,12 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallbac
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要订阅的佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 |
| callback |
Async
Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 | 注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
| callback | Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 | 注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
-
示例:
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){
console.info('Wear status: ' + data.value);
},
{interval: 10000000}
...
...
@@ -635,9 +582,9 @@ on(type: sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallbac
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_ACCELEROMETER)
## sensor.once(SensorType.SENSOR_TYPE_ID_ACCELEROMETER)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Async
Callback
<
AccelerometerResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback:
Callback
<
AccelerometerResponse
>
): void
监听加速度传感器的数据变化一次。
...
...
@@ -649,15 +596,11 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallba
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。 |
| callback |
Async
Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
| 是 | 注册一次加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
| callback | Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
| 是 | 注册一次加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(error,data){
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -666,9 +609,9 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallba
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION)
## sensor.once(SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Async
Callback
<
LinearAccelerometerResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:
Callback
<
LinearAccelerometerResponse
>
): void
监听线性加速度传感器数据变化一次。
...
...
@@ -680,15 +623,11 @@ once(type:sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCal
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 |
| callback |
Async
Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 | 注册一次线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
| callback | Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 | 注册一次线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -697,9 +636,9 @@ once(type:sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCal
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED)
## sensor.once(SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:Async
Callback
<
AccelerometerUncalibratedResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:
Callback
<
AccelerometerUncalibratedResponse
>
): void
监听未校准加速度传感器的数据变化一次。
...
...
@@ -711,15 +650,11 @@ once(type:sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:A
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 未校准加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
| callback |
Async
Callback
<
[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)
>
| 是 | 注册一次未校准加速度传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
| callback | Callback
<
[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)
>
| 是 | 注册一次未校准加速度传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -731,9 +666,9 @@ once(type:sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:A
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_GRAVITY)
## sensor.once(SensorType.SENSOR_TYPE_ID_GRAVITY)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Async
Callback
<
GravityResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_GRAVITY, callback:
Callback
<
GravityResponse
>
): void
监听重力传感器的数据变化一次。
...
...
@@ -743,15 +678,11 @@ once(type:sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback<G
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 重力传感器类型为SENSOR_TYPE_ID_GRAVITY。 |
| callback |
Async
Callback
<
[GravityResponse](#gravityresponse)
>
| 是 | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 |
| callback | Callback
<
[GravityResponse](#gravityresponse)
>
| 是 | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -760,9 +691,9 @@ once(type:sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback<G
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_GYROSCOPE)
## sensor.once(SensorType.SENSOR_TYPE_ID_GYROSCOPE)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Async
Callback
<
GyroscopeResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback:
Callback
<
GyroscopeResponse
>
): void
监听陀螺仪传感器的数据变化一次。
...
...
@@ -774,15 +705,11 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback&l
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。 |
| callback |
Async
Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
| callback | Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -791,9 +718,9 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback&l
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED)
## sensor.once(SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Async
Callback
<
GyroscopeUncalibratedResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:
Callback
<
GyroscopeUncalibratedResponse
>
): void
监听未校准陀螺仪传感器的数据变化一次。
...
...
@@ -805,15 +732,11 @@ once(type:sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Async
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback |
Async
Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
| callback | Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -825,9 +748,9 @@ once(type:sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Async
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION)
## sensor.once(SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback:Async
Callback
<
SignificantMotionResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback:
Callback
<
SignificantMotionResponse
>
): void
监听有效运动传感器的数据变化一次。
...
...
@@ -837,24 +760,20 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback:AsyncCal
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 有效运动传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
| callback |
Async
Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
| callback | Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) {
console.info('Scalar data: ' + data.scalar);
}
);
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION)
## sensor.once(SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback:Async
Callback
<
PedometerDetectionResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback:
Callback
<
PedometerDetectionResponse
>
): void
监听计步检测传感器数据变化一次。
...
...
@@ -866,24 +785,20 @@ once(type:sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback:AsyncCal
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
| callback |
Async
Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
| callback | Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(data) {
console.info('Scalar data: ' + data.scalar);
}
);
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_PEDOMETER)
## sensor.once(SensorType.SENSOR_TYPE_ID_PEDOMETER)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Async
Callback
<
PedometerResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_PEDOMETER, callback:
Callback
<
PedometerResponse
>
): void
监听计步器传感器数据变化一次。
...
...
@@ -895,24 +810,20 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback&l
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。 |
| callback |
Async
Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
| callback | Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) {
console.info('Steps: ' + data.steps);
}
);
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE)
## sensor.once(SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Async
Callback
<
AmbientTemperatureResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:
Callback
<
AmbientTemperatureResponse
>
): void
监听环境温度传感器数据变化一次。
...
...
@@ -922,24 +833,20 @@ once(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCal
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
| callback |
Async
Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
| callback | Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) {
console.info('Temperature: ' + data.temperature);
}
);
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD)
## sensor.once(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Async
Callback
<
MagneticFieldResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback:
Callback
<
MagneticFieldResponse
>
): void
监听磁场传感器数据变化一次。
...
...
@@ -949,15 +856,11 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallb
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。 |
| callback |
Async
Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
| callback | Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -966,9 +869,9 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallb
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED)
## sensor.once(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:Async
Callback
<
MagneticFieldUncalibratedResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:
Callback
<
MagneticFieldUncalibratedResponse
>
): void
监听未校准磁场传感器数据变化一次。
...
...
@@ -978,15 +881,11 @@ once(type:sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
| callback |
Async
Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
| callback | Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
...
...
@@ -998,9 +897,9 @@ once(type:sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_PROXIMITY)
## sensor.once(SensorType.SENSOR_TYPE_ID_PROXIMITY)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Async
Callback
<
ProximityResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_PROXIMITY, callback:
Callback
<
ProximityResponse
>
): void
监听接近光传感器数据变化一次。
...
...
@@ -1010,7 +909,7 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback&l
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。 |
| callback |
Async
Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
| callback | Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
-
示例:
```
...
...
@@ -1025,9 +924,9 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback&l
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_HUMIDITY)
## sensor.once(SensorType.SENSOR_TYPE_ID_HUMIDITY)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Async
Callback
<
HumidityResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_HUMIDITY, callback:
Callback
<
HumidityResponse
>
): void
监听湿度传感器数据变化一次。
...
...
@@ -1037,24 +936,20 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback<
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。 |
| callback |
Async
Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
| callback | Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) {
console.info('Humidity: ' + data.humidity);
}
);
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_BAROMETER)
## sensor.once(SensorType.SENSOR_TYPE_ID_BAROMETER)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Async
Callback
<
BarometerResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_BAROMETER, callback:
Callback
<
BarometerResponse
>
): void
监听气压计传感器数据变化一次。
...
...
@@ -1064,24 +959,20 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback&l
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。 |
| callback |
Async
Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
| callback | Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
console.info('Atmospheric pressure: ' + data.pressure);
}
);
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_HALL)
## sensor.once(SensorType.SENSOR_TYPE_ID_HALL)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_HALL, callback: Async
Callback
<
HallResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_HALL, callback:
Callback
<
HallResponse
>
): void
监听霍尔传感器数据变化一次。
...
...
@@ -1091,24 +982,20 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_HALL, callback: AsyncCallback<H
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 霍尔传感器类型为SENSOR_TYPE_ID_HALL。 |
| callback |
Async
Callback
<
[HallResponse](#hallresponse)
>
| 是 | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 |
| callback | Callback
<
[HallResponse](#hallresponse)
>
| 是 | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) {
console.info('Status: ' + data.status);
}
);
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT)
## sensor.once(SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Async
Callback
<
LightResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback:
Callback
<
LightResponse
>
): void
监听环境光传感器数据变化一次。
...
...
@@ -1118,24 +1005,20 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallba
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 |
| callback |
Async
Callback
<
[LightResponse](#lightresponse)
>
| 是 | 注册一次环境光传感器的回调函数,上报的数据类型为LightResponse。 |
| callback | Callback
<
[LightResponse](#lightresponse)
>
| 是 | 注册一次环境光传感器的回调函数,上报的数据类型为LightResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) {
console.info(' Illumination: ' + data.intensity);
}
);
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_ORIENTATION)
## sensor.once(SensorType.SENSOR_TYPE_ID_ORIENTATION)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Async
Callback
<
OrientationResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_ORIENTATION, callback:
Callback
<
OrientationResponse
>
): void
监听方向传感器数据变化一次。
...
...
@@ -1145,26 +1028,22 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: AsyncCallback
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 方向传感器类型为SENSOR_TYPE_ID_ORIENTATION。 |
| callback |
Async
Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
| callback | Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(data) {
console.info('The device rotates at an angle around the X axis: ' + data.beta);
console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
}
);
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR)
## sensor.once(SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Async
Callback
<
RotationVectorResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback:
Callback
<
RotationVectorResponse
>
): void
监听旋转矢量传感器数据变化一次。
...
...
@@ -1174,26 +1053,23 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: AsyncCall
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
| callback |
Async
Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
| callback | Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
console.info('Scalar quantity: ' + data.w);
}
);
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_HEART_RATE)
## sensor.once(SensorType.SENSOR_TYPE_ID_HEART_RATE)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Async
Callback
<
HeartRateResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_HEART_RATE, callback:
Callback
<
HeartRateResponse
>
): void
监听心率传感器数据变化一次。
...
...
@@ -1205,24 +1081,20 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: AsyncCallback&
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 心率传感器类型为SENSOR_TYPE_ID_HEART_RATE。 |
| callback |
Async
Callback
<
[HeartRateResponse](#heartrateresponse)
>
| 是 | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
| callback | Callback
<
[HeartRateResponse](#heartrateresponse)
>
| 是 | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function(error, data) {
if (error) {
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function(data) {
console.info("Heart rate: " + data.heartRate);
}
);
```
## sensor.once(
sensor.
SensorType.SENSOR_TYPE_ID_WEAR_DETECTION)
## sensor.once(SensorType.SENSOR_TYPE_ID_WEAR_DETECTION)
once(type:
sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Async
Callback
<
WearDetectionResponse
>
): void
once(type:
SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback:
Callback
<
WearDetectionResponse
>
): void
监听佩戴检测传感器数据变化一次。
...
...
@@ -1232,46 +1104,564 @@ once(type: sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallb
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 |
| callback |
Async
Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
| callback | Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
-
示例:
```
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(error, data) {
if (error) {
console.error("Failed to register data, error code is" + error.code + ", message: " + error.message);
return;
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) {
console.info("Wear status: "+ data.value);
}
);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_ACCELEROMETER)
off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback
<
AccelerometerResponse
>
): void
## sensor.off
取消订阅传感器数据。
**需要权限**
:ohos.permission.ACCELEROMETER, 该权限为系统权限
**系统能力**
:SystemCapability.Sensors.Sensor
off(type: SensorType, callback?: AsyncCallback
<
void
>
): void
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。 |
| callback | Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
| 是 | 取消注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
-
示例:
```
function callback(data) {
console.info('x-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED)
off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback
<
AccelerometerUncalibratedResponse
>
): void
取消订阅传感器数据。
**需要权限**
:ohos.permission.ACCELEROMETER, 该权限为系统权限
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的传感器类型。 |
| callback | AsyncCallback
<
void
>
| 是 | 取消订阅的传感器的回调函数,表示接口调用是否成功。 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的未校准加速度计传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback
<
[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)
>
| 是 | 取消注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
-
示例:
```
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(error) {
if (error) {
console.error("Failed to unsubscribe from acceleration sensor data. Error code: " + error.code + "; message: " + error.message);
return;
}
console.info("Succeeded in unsubscribing from acceleration sensor data.");
}
);
```
```
function callback(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
console.info('X-coordinate bias: ' + data.biasX);
console.info('Y-coordinate bias: ' + data.biasY);
console.info('Z-coordinate bias: ' + data.biasZ);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT)
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback
<
LightResponse
>
): void
取消订阅传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 |
| callback | Callback
<
[LightResponse](#lightresponse)
>
| 是 | 取消注册环境光传感器的回调函数,上报的数据类型为LightResponse。 |
-
示例:
```
function callback(data) {
console.info(' Illumination: ' + data.intensity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE)
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback
<
AmbientTemperatureResponse
>
): void
取消订阅传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
| callback | Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 | 取消注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
-
示例:
```
function callback(data) {
console.info('Temperature: ' + data.temperature);
}
sensor.off( sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE)
off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback
<
BarometerResponse
>
): void
取消订阅传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。 |
| callback | Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 | 取消注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
-
示例:
```
function callback(data) {
console.info('Atmospheric pressure: ' + data.pressure);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_GRAVITY)
off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback
<
GravityResponse
>
): void
取消订阅传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的重力传感器类型为SENSOR_TYPE_ID_GRAVITY。 |
| callback | Callback
<
[GravityResponse](#gravityresponse)
>
| 是 | 取消注册注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |
-
示例:
```
function callback(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
}
sensor.off( sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_GYROSCOPE)
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback
<
GyroscopeResponse
>
): void
取消订阅传感器数据。
**需要权限**
:ohos.permission.GYROSCOPE, 该权限为系统权限
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。 |
| callback | Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 | 取消注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
-
示例:
```
function callback(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED)
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback
<
GyroscopeResponse
>
): void
取消订阅传感器数据。
**需要权限**
:ohos.permission.GYROSCOPE, 该权限为系统权限
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback | Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 | 取消注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
-
示例:
```
function callback(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_HALL)
off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback
<
HallResponse
>
): void
取消订阅传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的霍尔传感器类型为SENSOR_TYPE_ID_HALL。 |
| callback | Callback
<
[HallResponse](#hallresponse)
>
| 是 | 取消注册霍尔传感器的回调函数,上报的数据类型为
HallResponse。 |
-
示例:
```
function callback(data) {
console.info('Status: ' + data.status);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_HEART_RATE)
off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback
<
HeartRateResponse
>
): void
取消订阅传感器数据。
**需要权限**
:ohos.permission.READ_HEALTH_DATA
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)[
SensorType
]
(#sensortype) | 是 | 要取消订阅的心率传感器类型为SENSOR_TYPE_ID_HEART_RATE。 |
| callback | Callback
<
[HeartRateResponse](#heartrateresponse)
>
| 是 | 取消注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
-
示例:
```
function callback(data) {
console.info("Heart rate: " + data.heartRate);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_HUMIDITY)
off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback
<
HumidityResponse
>
): void
取消订阅传感器数据。
**需要权限**
:ohos.permission.READ_HEALTH_DATA,该权限为系统权限
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。 |
| callback | Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 | 取消注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
-
示例:
```
function callback(data) {
console.info('Humidity: ' + data.humidity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION)
off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback
<
LinearAccelerometerResponse
>
): void
取消订阅传感器数据。
**需要权限**
:ohos.permission.ACCELEROMETER,该权限为系统权限
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 |
| callback | Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 | 取消注册性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
-
示例:
```
function callback(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD)
off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback
<
MagneticFieldResponse
>
): void
取消订阅传感器数据。
**需要权限**
:ohos.permission.ACCELEROMETER,该权限为系统权限
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。 |
| callbackcallback | Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 | 取消注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
-
示例:
```
function callback(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED)
off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback
<
MagneticFieldUncalibratedResponse
>
): void
取消订阅传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 | 取消注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
-
示例:
```
function callback(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
console.info('X-coordinate bias: ' + data.biasX);
console.info('Y-coordinate bias: ' + data.biasY);
console.info('Z-coordinate bias: ' + data.biasZ);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_ORIENTATION)
off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback
<
OrientationResponse
>
): void
取消订阅传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的方向传感器类型为SENSOR_TYPE_ID_ORIENTATION |
| callback | Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 | 取消注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
-
示例:
```
function callback(data) {
console.info('The device rotates at an angle around the X axis: ' + data.beta);
console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_PEDOMETER)
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback
<
PedometerResponse
>
): void
取消订阅传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。 |
| callback | Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 | 取消注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
-
示例;
```
function callback(data) {
console.info('Steps: ' + data.steps);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION)
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback
<
PedometerDetectionResponse
>
): void
取消订阅传感器数据。
**需要权限**
:ohos.permission.ACTIVITY_MOTION
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
| callback | Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 | 取消注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
-
示例:
```
function callback(data) {
console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_PROXIMITY)
off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback
<
ProximityResponse
>
): void
取消订阅传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。 |
| callback | Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 | 取消注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
-
示例:
```
function callback(data) {
console.info('Distance: ' + data.distance);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR)
off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback
<
RotationVectorResponse
>
): void
取消订阅传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
| callback | Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 | 取消注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
-
示例:
```
function callback(data) {
console.info('X-coordinate component: ' + data.x);
console.info('Y-coordinate component: ' + data.y);
console.info('Z-coordinate component: ' + data.z);
console.info('Scalar quantity: ' + data.w);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION)
off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback
<
SignificantMotionResponse
>
): void
取消订阅传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的大幅动作传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
| callback | Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 | 取消注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
-
示例:
```
function callback(data) {
console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
```
## sensor.off(SensorType.SENSOR_TYPE_ID_WEAR_DETECTION)
off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback
<
WearDetectionResponse
>
): void
取消订阅传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorType
](
#sensortype
)
| 是 | 要取消订阅的佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 |
| callback | Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 | 取消注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
-
示例:
```
function accCallback(data) {
console.info('Wear status: ' + data.value);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
```
## sensor.transformCoordinateSystem
...
...
@@ -1973,9 +2363,9 @@ createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number&
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
|
x | number | 是 | 是 | 设备围绕x轴的旋转
角度,单位 : rad。 |
|
y | number | 是 | 是 | 设备围绕y轴的旋转
角度,单位 : rad。 |
|
z | number | 是 | 是 | 设备围绕z轴的旋转
角度,单位 : rad。 |
|
alpha | number | 是 | 是 | 设备围绕 Z 轴旋转一定
角度,单位 : rad。 |
|
beta | number | 是 | 是 | 设备围绕 X轴旋转一定
角度,单位 : rad。 |
|
gamma | number | 是 | 是 | 设备围绕 Y轴旋转一定
角度,单位 : rad。 |
## RotationVectorResponse
...
...
@@ -1990,6 +2380,7 @@ createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number&
| x | number | 是 | 是 | 旋转矢量x轴分量。 |
| y | number | 是 | 是 | 旋转矢量y轴分量。 |
| z | number | 是 | 是 | 旋转矢量z轴分量。 |
| w | number | 是 | 是 | 标量。 |
## GyroscopeResponse
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录