20180505_android传感器种类及获取

介绍下android的各种传感器以及如何查看手机支持哪些传感器。

[TOC]

获取传感器列表

1
2
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);

传感器介绍

google翻译的,随便看看好了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
String type;
switch (s.getType()) {
case Sensor.TYPE_ACCELEROMETER:
type = "加速度传感器";
break;
case Sensor.TYPE_MAGNETIC_FIELD:
type = "磁场传感器";
break;
case Sensor.TYPE_ORIENTATION:
type = "方向传感器";
break;
case Sensor.TYPE_GYROSCOPE:
type = "陀螺仪传感器";
break;
case Sensor.TYPE_LIGHT:
type = "光线传感器";
break;
case Sensor.TYPE_PRESSURE:
type = "压力传感器";
break;
case Sensor.TYPE_TEMPERATURE:
type = "温度传感器";
break;
case Sensor.TYPE_PROXIMITY:
type = "接近传感器";
break;
case Sensor.TYPE_GRAVITY:
type = "重力传感器";
break;
case Sensor.TYPE_LINEAR_ACCELERATION:
type = "线性加速度传感器";
break;
case Sensor.TYPE_ROTATION_VECTOR:
type = "旋转矢量传感器";
break;
case Sensor.TYPE_RELATIVE_HUMIDITY:
type = "相对湿度传感器";
break;
case Sensor.TYPE_AMBIENT_TEMPERATURE:
type = "环境温度传感器";
break;
case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED:
type = "磁场传感器(未经校准)";
break;
case Sensor.TYPE_GAME_ROTATION_VECTOR:
type = "游戏旋转矢量传感器";
break;
case Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
type = "陀螺仪传感器(未经校准)";
break;
case Sensor.TYPE_SIGNIFICANT_MOTION:
type = "特殊动作触发传感器";
break;
case Sensor.TYPE_STEP_DETECTOR:
type = "步数探测传感器";
break;
case Sensor.TYPE_STEP_COUNTER:
type = "步数计数传感器";
break;
case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR:
type = "地磁旋转矢量传感器";
break;
case Sensor.TYPE_HEART_RATE:
type = "心率传感器";
break;
case Sensor.TYPE_POSE_6DOF:
type = "POSE_6DOF传感器";
break;
case Sensor.TYPE_STATIONARY_DETECT:
type = "静止检测传感器";
break;
case Sensor.TYPE_MOTION_DETECT:
type = "运动检测传感器";
break;
case Sensor.TYPE_HEART_BEAT:
type = "心跳传感器";
break;
case Sensor.TYPE_LOW_LATENCY_OFFBODY_DETECT:
type = "低延迟身体检测传感器";
break;
case Sensor.TYPE_ACCELEROMETER_UNCALIBRATED:
type = "加速度传感器(未经校准)";
break;
default:
type = "其它传感器";
break;
}

源码地址

AndroidSensorStudy

Fork me on GitHub