• Home
Name Date Size #Lines LOC

..--

AppScope/12-May-2024-3633

entry/12-May-2024-848772

hvigor/12-May-2024-2322

screenshots/device/12-May-2024-

.gitignoreD12-May-2024121 1010

README.mdD12-May-2024512 168

README_zh.mdD12-May-20241.9 KiB6339

build-profile.json5D12-May-20241 KiB4241

hvigorfile.tsD12-May-2024158 21

hvigorwD12-May-20242.1 KiB6228

hvigorw.batD12-May-20242 KiB7256

oh-package.json5D12-May-2024816 2625

ohosTest.mdD12-May-2024696 1310

README.md

1# Device Management - Sensor
2
3### Introduction
4
5This sample uses the orientation sensor APIs to implement the compass effect.
6
7### Usage
8
9When you rotate your device, the compass pointer rotates with it. The rotation angle for true north is displayed in the lower part of the home screen of the sample app.
10
11### Constraints
12
13After opening the sample app, you need to make a figure 8 until the compass is calibrated.
14
15This sample can only be run on standard-system devices. (Currently, only wagner is supported.)
16

README_zh.md

1# 传感器
2
3### 介绍
4
5本示例使用[@ohos.sensor](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-sensor-service-kit/js-apis-sensor.md) 中的方向传感器相关接口,实现指南针的功能。
6
7### 效果预览
8
9|主页|
10|---|
11|![](./screenshots/device/sensor.png)|
12
13使用说明
14
15转动设备,指针跟随转动,转动的角度为偏离正北方的角度,并在界面下方显示。
16
17### 工程目录
18```
19entry/src/main/ets/
20|---entryAbility                           // 入口文件
21|---pages
22|   |---index.ets                          // 首页
23|---util                                   // 日志工具
24```
25
26### 具体实现
27
28* 指南针:在主页直接引入sensor对象,使用sensor.on()监听传感器变化,当传感器发生变化时会返回数据data,其中包含alpha属性,使用
29Math.round(alpha)得出他的整数角度,配合Image组件的旋转属性rotate来展示到界面中。源码参考[Index.ets](entry/src/main/ets/pages/Index.ets) 。
30
31### 相关权限
32
33[ohos.permission.VIBRATE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionvibrate)
34
35### 依赖
36
37不涉及。
38
39### 约束与限制
40
411.打开应用后需要对传感器进行画8校准。
42
432.本示例仅支持在标准系统上运行。
44
453.本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400 构建 2023年4月7日)及以上版本才可编译运行。
46
474.本示例需要特殊模块与特定传感器,目前该功能仅支持部分机型。
48
495.本示例已适配API version 9版本SDK,版本号:3.2.11.9。
50
51### 下载
52
53如需单独下载本工程,执行如下命令:
54
55```
56git init
57git config core.sparsecheckout true
58echo code/BasicFeature/DeviceManagement/Sensor/ > .git/info/sparse-checkout
59git remote add origin https://gitee.com/openharmony/applications_app_samples.git
60git pull origin master
61```
62
63