Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
469d3f98
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看板
未验证
提交
469d3f98
编写于
7月 10, 2023
作者:
O
openharmony_ci
提交者:
Gitee
7月 10, 2023
浏览文件
操作
浏览文件
下载
差异文件
!20617 整改docs规范扫描
Merge pull request !20617 from liyaoyao/master
上级
a8424bab
80756b25
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
1600 addition
and
1532 deletion
+1600
-1532
zh-cn/application-dev/device/sensor-guidelines.md
zh-cn/application-dev/device/sensor-guidelines.md
+18
-15
zh-cn/application-dev/reference/apis/js-apis-sensor.md
zh-cn/application-dev/reference/apis/js-apis-sensor.md
+1509
-1445
zh-cn/application-dev/reference/apis/js-apis-system-sensor.md
...n/application-dev/reference/apis/js-apis-system-sensor.md
+73
-72
未找到文件。
zh-cn/application-dev/device/sensor-guidelines.md
浏览文件 @
469d3f98
...
...
@@ -33,10 +33,11 @@
2.
以下场景以加速度传感器ACCELEROMETER为例。展示持续监听传感器接口的调用结果。
```
j
s
```
t
s
import
sensor
from
"
@ohos.sensor
"
;
sensor
.
on
(
sensor
.
SensorId
.
ACCELEROMETER
,
function
(
data
){
console
.
info
(
"
Data obtained successfully. x:
"
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
// 获取数据成功
sensor
.
on
(
sensor
.
SensorId
.
ACCELEROMETER
,
function
(
data
)
{
console
.
info
(
"
Succeeded in obtaining data. x:
"
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
// 获取数据成功
});
```
...
...
@@ -44,7 +45,7 @@
3.
注销传感器数据监听。
```
j
s
```
t
s
import
sensor
from
"
@ohos.sensor
"
;
sensor
.
off
(
sensor
.
SensorId
.
ACCELEROMETER
);
```
...
...
@@ -53,10 +54,11 @@
4.
获取一次传感器数据变化。
```
j
s
```
t
s
import
sensor
from
"
@ohos.sensor
"
;
sensor
.
once
(
sensor
.
SensorId
.
ACCELEROMETER
,
function
(
data
)
{
console
.
info
(
"
Data obtained successfully. x:
"
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
// 获取数据成功
sensor
.
once
(
sensor
.
SensorId
.
ACCELEROMETER
,
function
(
data
)
{
console
.
info
(
"
Succeeded in obtaining data. x:
"
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
// 获取数据成功
});
```
...
...
@@ -64,15 +66,16 @@
若接口调用不成功,建议使用try/catch语句捕获代码中可能出现的错误信息。例如:
```
j
s
```
t
s
import sensor from "@ohos.sensor";
try {
sensor.once(sensor.SensorId.ACCELEROMETER, function(data) {
console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z); // 获取数据成功
});
} catch (error) {
console.error("Get sensor data error. data:" + error.data, " msg:", error.message);
}
try {
sensor.once(sensor.SensorId.ACCELEROMETER, function (data) {
console.info("Succeeded in obtaining data. x: " + data.x + "y: " + data.y + "z: " + data.z); // 获取数据成功
});
} catch (error) {
console.error(
`Failed to get sensor data. Code: ${error.code}, message: ${error.message}`
);
}
```
## 相关实例
...
...
zh-cn/application-dev/reference/apis/js-apis-sensor.md
浏览文件 @
469d3f98
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-system-sensor.md
浏览文件 @
469d3f98
...
...
@@ -37,16 +37,16 @@ import sensor from '@system.sensor';
**示例:**
```
j
s
```
t
s
sensor
.
subscribeAccelerometer
({
interval
:
'
normal
'
,
success
:
function
(
ret
)
{
console
.
log
(
'
X-axis data:
'
+
ret
.
x
);
console
.
log
(
'
Y-axis data:
'
+
ret
.
y
);
console
.
log
(
'
Z-axis data:
'
+
ret
.
z
);
success
:
function
(
ret
)
{
console
.
info
(
'
Succeeded in subscribing.
X-axis data:
'
+
ret
.
x
);
console
.
info
(
'
Succeeded in subscribing.
Y-axis data:
'
+
ret
.
y
);
console
.
info
(
'
Succeeded in subscribing.
Z-axis data:
'
+
ret
.
z
);
},
fail
:
function
(
data
,
code
)
{
console
.
error
(
'
Subscription failed. Code:
'
+
code
+
'
; Data:
'
+
data
);
fail
:
function
(
data
,
code
)
{
console
.
error
(
`Failed to subscription. Code:
${
code
}
, data:
${
data
}
`
);
},
});
```
...
...
@@ -66,7 +66,7 @@ unsubscribeAccelerometer(): void
**示例:**
```
j
s
```
t
s
sensor
.
unsubscribeAccelerometer
();
```
...
...
@@ -86,13 +86,13 @@ sensor.unsubscribeAccelerometer();
**示例:**
```
j
s
```
t
s
sensor
.
subscribeCompass
({
success
:
function
(
ret
)
{
console
.
log
(
'
Get data direction:
'
+
ret
.
direction
);
success
:
function
(
ret
)
{
console
.
info
(
'
Succeeded in subscribing.
Get data direction:
'
+
ret
.
direction
);
},
fail
:
function
(
data
,
code
)
{
console
.
error
(
'
Subscription failed. Code:
'
+
code
+
'
; Data:
'
+
data
);
fail
:
function
(
data
,
code
)
{
console
.
error
(
`Failed to subscription. Code:
${
code
}
, data:
${
data
}
`
);
},
});
```
...
...
@@ -110,7 +110,7 @@ unsubscribeCompass(): void
**示例:**
```
j
s
```
t
s
sensor
.
unsubscribeCompass
();
```
...
...
@@ -130,13 +130,14 @@ sensor.unsubscribeCompass();
**示例:**
```
j
s
```
t
s
sensor
.
subscribeProximity
({
success
:
function
(
ret
)
{
console
.
log
(
'
Get data distance:
'
+
ret
.
distance
);
success
:
function
(
ret
)
{
console
.
info
(
'
Succeeded in subscribing.
Get data distance:
'
+
ret
.
distance
);
},
fail
:
function
(
data
,
code
)
{
console
.
error
(
'
Subscription failed. Code:
'
+
code
+
'
; Data:
'
+
data
);
fail
:
function
(
data
,
code
)
{
console
.
error
(
`Failed to subscription. Code:
${
code
}
, data:
${
data
}
`
);
},
});
```
...
...
@@ -154,7 +155,7 @@ unsubscribeProximity(): void
**示例:**
```
j
s
```
t
s
sensor
.
unsubscribeProximity
();
```
...
...
@@ -174,13 +175,13 @@ sensor.unsubscribeProximity();
**示例:**
```
j
s
```
t
s
sensor
.
subscribeLight
({
success
:
function
(
ret
)
{
console
.
log
(
'
Get data intensity:
'
+
ret
.
intensity
);
success
:
function
(
ret
)
{
console
.
info
(
'
Succeeded in subscribing.
Get data intensity:
'
+
ret
.
intensity
);
},
fail
:
function
(
data
,
code
)
{
console
.
error
(
'
Subscription failed. Code:
'
+
code
+
'
; Data:
'
+
data
);
fail
:
function
(
data
,
code
)
{
console
.
error
(
`Failed to subscription. Code:
${
code
}
, data:
${
data
}
`
);
},
});
```
...
...
@@ -198,7 +199,7 @@ unsubscribeLight(): void
**示例:**
```
j
s
```
t
s
sensor
.
unsubscribeLight
();
```
...
...
@@ -220,13 +221,13 @@ sensor.unsubscribeLight();
**示例:**
```
j
s
```
t
s
sensor
.
subscribeStepCounter
({
success
:
function
(
ret
)
{
console
.
log
(
'
Get step value:
'
+
ret
.
steps
);
success
:
function
(
ret
)
{
console
.
info
(
'
Succeeded in subscribing.
Get step value:
'
+
ret
.
steps
);
},
fail
:
function
(
data
,
code
)
{
console
.
log
(
'
Subscription failed. Code:
'
+
code
+
'
; Data:
'
+
data
);
fail
:
function
(
data
,
code
)
{
console
.
error
(
`Failed to subscription. Code:
${
code
}
, data:
${
data
}
`
);
},
});
```
...
...
@@ -246,7 +247,7 @@ unsubscribeStepCounter(): void
**示例:**
```
j
s
```
t
s
sensor
.
unsubscribeStepCounter
();
```
...
...
@@ -267,13 +268,13 @@ subscribeBarometer(options: SubscribeBarometerOptions): void
**示例:**
```
j
s
```
t
s
sensor
.
subscribeBarometer
({
success
:
function
(
ret
)
{
console
.
log
(
'
Get data value:
'
+
ret
.
pressure
);
success
:
function
(
ret
)
{
console
.
info
(
'
Succeeded in subscribing.
Get data value:
'
+
ret
.
pressure
);
},
fail
:
function
(
data
,
code
)
{
console
.
log
(
'
Subscription failed. Code:
'
+
code
+
'
; Data:
'
+
data
);
fail
:
function
(
data
,
code
)
{
console
.
error
(
`Failed to subscription. Code:
${
code
}
, data:
${
data
}
`
);
},
});
```
...
...
@@ -292,7 +293,7 @@ unsubscribeBarometer(): void
**示例:**
```
j
s
```
t
s
sensor
.
unsubscribeBarometer
();
```
...
...
@@ -315,13 +316,13 @@ sensor.unsubscribeBarometer();
**示例:**
```
j
s
```
t
s
sensor
.
subscribeHeartRate
({
success
:
function
(
ret
)
{
console
.
log
(
'
Get heartrate value:
'
+
ret
.
heartRate
);
success
:
function
(
ret
)
{
console
.
info
(
'
Succeeded in subscribing.
Get heartrate value:
'
+
ret
.
heartRate
);
},
fail
:
function
(
data
,
code
)
{
console
.
log
(
'
Subscription failed. Code:
'
+
code
+
'
; Data:
'
+
data
);
fail
:
function
(
data
,
code
)
{
console
.
error
(
`Failed to subscription. Code:
${
code
}
, data:
${
data
}
`
);
},
});
```
...
...
@@ -342,7 +343,7 @@ unsubscribeHeartRate(): void
**示例:**
```
j
s
```
t
s
sensor
.
unsubscribeHeartRate
();
```
...
...
@@ -362,13 +363,13 @@ sensor.unsubscribeHeartRate();
**示例:**
```
j
s
```
t
s
sensor
.
subscribeOnBodyState
({
success
:
function
(
ret
)
{
console
.
log
(
'
Get on-body state value:
'
+
ret
.
value
);
success
:
function
(
ret
)
{
console
.
info
(
'
Succeeded in subscribing.
Get on-body state value:
'
+
ret
.
value
);
},
fail
:
function
(
data
,
code
)
{
console
.
log
(
'
Subscription failed. Code:
'
+
code
+
'
; Data:
'
+
data
);
fail
:
function
(
data
,
code
)
{
console
.
error
(
`Failed to subscription. Code:
${
code
}
, data:
${
data
}
`
);
},
});
```
...
...
@@ -386,7 +387,7 @@ unsubscribeOnBodyState(): void
**示例:**
```
j
s
```
t
s
sensor
.
unsubscribeOnBodyState
();
```
...
...
@@ -406,13 +407,13 @@ sensor.unsubscribeOnBodyState();
**示例:**
```
j
s
```
t
s
sensor
.
getOnBodyState
({
success
:
function
(
ret
)
{
console
.
log
(
'
On body state:
'
+
ret
.
value
);
success
:
function
(
ret
)
{
console
.
info
(
'
Succeeded in subscribing.
On body state:
'
+
ret
.
value
);
},
fail
:
function
(
data
,
code
)
{
console
.
log
(
'
Subscription failed. Code:
'
+
code
+
'
; Data:
'
+
data
);
fail
:
function
(
data
,
code
)
{
console
.
error
(
`Failed to subscription. Code:
${
code
}
, data:
${
data
}
`
);
},
});
```
...
...
@@ -435,17 +436,17 @@ sensor.getOnBodyState({
**示例:**
```
j
s
```
t
s
sensor
.
subscribeDeviceOrientation
({
interval
:
'
normal
'
,
success
:
function
(
ret
)
{
console
.
log
(
'
Alpha data:
'
+
ret
.
alpha
);
console
.
log
(
'
Beta data:
'
+
ret
.
beta
);
console
.
log
(
'
Gamma data:
'
+
ret
.
gamma
);
success
:
function
(
ret
)
{
console
.
info
(
'
Succeeded in subscribing.
Alpha data:
'
+
ret
.
alpha
);
console
.
info
(
'
Succeeded in subscribing.
Beta data:
'
+
ret
.
beta
);
console
.
info
(
'
Succeeded in subscribing.
Gamma data:
'
+
ret
.
gamma
);
},
fail
:
function
(
data
,
code
)
{
console
.
error
(
'
Subscription failed. Code:
'
+
code
+
'
; Data:
'
+
data
);
}
fail
:
function
(
data
,
code
)
{
console
.
error
(
`Failed to subscription. Code:
${
code
}
, data:
${
data
}
`
);
}
});
```
...
...
@@ -462,7 +463,7 @@ unsubscribeDeviceOrientation(): void
**示例:**
```
j
s
```
t
s
sensor
.
unsubscribeDeviceOrientation
();
```
...
...
@@ -486,16 +487,16 @@ sensor.unsubscribeDeviceOrientation();
**示例:**
```
j
s
```
t
s
sensor
.
subscribeGyroscope
({
interval
:
'
normal
'
,
success
:
function
(
ret
)
{
console
.
log
(
'
X-axis data:
'
+
ret
.
x
);
console
.
log
(
'
Y-axis data:
'
+
ret
.
y
);
console
.
log
(
'
Z-axis data:
'
+
ret
.
z
);
success
:
function
(
ret
)
{
console
.
info
(
'
Succeeded in subscribing.
X-axis data:
'
+
ret
.
x
);
console
.
info
(
'
Succeeded in subscribing.
Y-axis data:
'
+
ret
.
y
);
console
.
info
(
'
Succeeded in subscribing.
Z-axis data:
'
+
ret
.
z
);
},
fail
:
function
(
data
,
code
)
{
console
.
error
(
'
Subscription failed. Code:
'
+
code
+
'
; data:
'
+
data
);
fail
:
function
(
data
,
code
)
{
console
.
error
(
`Failed to subscription. Code:
${
code
}
, data:
${
data
}
`
);
}
});
```
...
...
@@ -515,7 +516,7 @@ unsubscribeGyroscope(): void
**示例:**
```
j
s
```
t
s
sensor
.
unsubscribeGyroscope
();
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录