一种 Android 加速度传感器应用的通用解决

方案

5

10

15

20

25

30

35

40

摘要:加速度传感器是在 Android 移动设备上使用最广泛的传感器类型,使用加速度传感器

开发的移动应用层出不穷,但是目前,在业界还没有一种针对该类型应用的较为通用的实现

方法。为了提高开发效率,缩短开发周期,本文提出了一种 Android 加速度传感器应用的通

用解决方案。本文首先深入剖析了 Android 移动终端中加速度传感器的工作原理,接着根据

不同的使用场景和不同的屏幕方向,分别详细阐述了利用加速度传感器实现场景中物体运动

状态变化的通用设计方案,最后,在此基础上提出了 Android 加速度传感器应用的通用程序

框架,并以实现物体的重力感应效果为例,具体说明了使用该程序框架开发 Android 加速度

传感器应用的开发流程,从而全面且详尽地提出了开发 Android 加速度传感器应用过程中从

功能设计到编码实现的整个解决方案。

关键词:Android;加速度传感器;重力感应;移动应用框架

中图分类号:TP311.1

A General Solution to Acceleration Sensor Application

Based on Android Platform

Liu Ying, Huang Xiaojun

(School of Information and Communication Engineering, Beijing University of Posts and

Telecommunications, Beijing 100876)

Abstract: The acceleration sensor is the most popular sensor on mobile devices. More and more

applications are developed using acceleration sensor, but there is not a general method for

implementation. This paper provides a general solution to acceleration sensor application based on

Android platform, in order to improve design and implementation efficiency and save time. This

paper analyzes the principles of the Android acceleration sensor in depth, describes how to design

the movement style in detail according to different application scenes and different screen

orientations, and implements a general program framework of acceleration sensor application.

Besides, this paper uses gravity induction phenomenon of a ball as an example, shows the entire

workflow of how to develop an acceleration sensor application using this program framework.

Key words: Android; acceleration sensor; gravity induction; mobile application framework

0 引言

Android 平台中有许多令用户和开发人员津津乐道的特性,其中最令人眼前一亮的就是

Android 平台上的各种传感器了,利用传感器可以开发出包括游戏类应用在内的很多新奇的

应用。传感器提供了方便的交互方式,用户不需要进行触摸或者按键操作,而是通过检测移

动设备本身的状态,并获取相应的参数值就可以实现预期的效果。

加速度传感器能够有效地跟踪移动设备的运动状态,并且,它在移动设备上的使用范围

极其广泛,几乎所有的 Android 移动设备上都安装有加速度传感器。目前,加速度传感器应

用已经成为移动应用的重要组成部分,例如,在游戏类应用中比较常见的物体重力感应效果,

-1-

就是使用移动设备中的加速度传感器实现的。利用加速度传感器的特性开发移动应用,已成

为 Android 移动应用开发领域