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