android获取传感器列表

来源:互联网 发布:怎么在淘宝头条上发帖 编辑:程序博客网 时间:2024/06/03 20:41

本文介绍如何获取android设备所支持的传感器列表。


目前,android 4.4 (API等级19)支持以下传感器:

TYPE_ACCELEROMETER加速度传感器,单位是m/s2,测量应用于设备X、Y、Z轴上的加速度传感器类型值(Sensor Type):1 (0x00000001)TYPE_AMBIENT_TEMPERATURE温度传感器,单位是℃传感器类型值(Sensor Type): 13 (0x0000000d)TYPE_GAME_ROTATION_VECTOR游戏动作传感器,不收电磁干扰影响传感器类型值(Sensor Type):15 (0x0000000f)TYPE_GEOMAGNETIC_ROTATION_VECTOR地磁旋转矢量传感器,提供手机的旋转矢量,当手机处于休眠状态时,仍可以记录设备的方位传感器类型值(Sensor Type):20 (0x00000014)TYPE_GRAVITY重力传感器,单位是m/s2,测量应用于设备X、Y、Z轴上的重力传感器类型值(Sensor Type):9 (0x00000009)TYPE_GYROSCOPE陀螺仪传感器,单位是rad/s,测量设备x、y、z三轴的角加速度传感器类型值(Sensor Type):4 (0x00000004)TYPE_GYROSCOPE_UNCALIBRATED未校准陀螺仪传感器,提供原始的,未校准、补偿的陀螺仪数据,用于后期处理和融合定位数据传感器类型值(Sensor Type):16 (0x00000010)TYPE_LIGHT光线感应传感器,单位lx,检测周围的光线强度传感器类型值(Sensor Type):5 (0x00000005)TYPE_LINEAR_ACCELERATION线性加速度传感器,单位是m/s2,该传感器是获取加速度传感器去除重力的影响得到的数据传感器类型值(Sensor Type):10 (0x0000000a)TYPE_MAGNETIC_FIELD磁力传感器,单位是uT(微特斯拉),测量设备周围三个物理轴(x,y,z)的磁场传感器类型值(Sensor Type):2 (0x00000002)TYPE_MAGNETIC_FIELD_UNCALIBRATED未校准磁力传感器,提供原始的,未校准的磁场数据传感器类型值(Sensor Type):14 (0x0000000e)TYPE_ORIENTATION方向传感器,测量设备围绕三个物理轴(x,y,z)的旋转角度传感器类型值(Sensor Type):3 (0x00000003)TYPE_PRESSURE压力传感器,单位是hPa(百帕斯卡),返回当前环境下的压强传感器类型值(Sensor Type):6 (0x00000006)TYPE_PROXIMITY距离传感器,单位是cm,用来测量某个对象到屏幕的距离传感器类型值(Sensor Type):8 (0x00000008)TYPE_RELATIVE_HUMIDITY湿度传感器,单位是%,来测量周围环境的相对湿度传感器类型值(Sensor Type):12 (0x0000000c)TYPE_ROTATION_VECTOR旋转矢量传感器,旋转矢量代表设备的方向传感器类型值(Sensor Type):11 (0x0000000b)TYPE_SIGNIFICANT_MOTION特殊动作触发传感器传感器类型值(Sensor Type):17 (0x00000011)TYPE_STEP_COUNTER计步传感器传感器类型值(Sensor Type):19 (0x00000013)TYPE_STEP_DETECTOR步行检测传感器,用户每走一步就触发一次事件传感器类型值(Sensor Type):18 (0x00000012)TYPE_TEMPERATURE温度传感器,目前已被TYPE_AMBIENT_TEMPERATURE替代传感器类型值(Sensor Type):7 (0x00000007)

获取传感器列表的代码如下:

package com.example.androidtest;import java.util.List;import android.os.Bundle;import android.annotation.SuppressLint;import android.app.Activity;import android.content.Context;import android.hardware.Sensor;import android.hardware.SensorManager;import android.view.Menu;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);getSensorList();}@SuppressLint("NewApi")private void getSensorList() {// 获取传感器管理器SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);// 获取全部传感器列表List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);// 打印每个传感器信息StringBuilder strLog = new StringBuilder();int iIndex = 1;for (Sensor item : sensors) {strLog.append(iIndex + ".");strLog.append("Sensor Type - " + item.getType() + "\r\n");strLog.append("Sensor Name - " + item.getName() + "\r\n");strLog.append("Sensor Version - " + item.getVersion() + "\r\n");strLog.append("Sensor Vendor - " + item.getVendor() + "\r\n");strLog.append("Maximum Range - " + item.getMaximumRange() + "\r\n");strLog.append("Minimum Delay - " + item.getMinDelay() + "\r\n");strLog.append("Power - " + item.getPower() + "\r\n");strLog.append("Resolution - " + item.getResolution() + "\r\n");strLog.append("\r\n");iIndex++;}System.out.println(strLog.toString());}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.activity_main, menu);return true;}}

以三星Note3为例,其支持的传感器如下:

1.Sensor Type - 1Sensor Name - MPU6500 Acceleration SensorSensor Version - 1Sensor Vendor - InvensenseMaximum Range - 19.6133Minimum Delay - 5000Power - 0.25Resolution - 5.985504E-42.Sensor Type - 2Sensor Name - YAS532 Magnetic SensorSensor Version - 1Sensor Vendor - Yamaha CorporationMaximum Range - 1200.0Minimum Delay - 10000Power - 6.0Resolution - 0.063.Sensor Type - 14Sensor Name - YAS532 Uncalibrated Magnetic SensorSensor Version - 1Sensor Vendor - Yamaha CorporationMaximum Range - 1200.0Minimum Delay - 10000Power - 6.0Resolution - 0.064.Sensor Type - 4Sensor Name - MPU6500 Gyroscope SensorSensor Version - 1Sensor Vendor - InvensenseMaximum Range - 8.726646Minimum Delay - 5000Power - 6.1Resolution - 2.663161E-45.Sensor Type - 6Sensor Name - Barometer SensorSensor Version - 1Sensor Vendor - BOSCHMaximum Range - 1013.25Minimum Delay - 66700Power - 1.0Resolution - 1.06.Sensor Type - 8Sensor Name - MAX88921 Proximity SensorSensor Version - 1Sensor Vendor - MAXIM, Inc.Maximum Range - 8.0Minimum Delay - 0Power - 0.75Resolution - 8.07.Sensor Type - 5Sensor Name - MAX88921 RGB SensorSensor Version - 1Sensor Vendor - MAXIM, Inc.Maximum Range - 60000.0Minimum Delay - 200000Power - 0.75Resolution - 1.08.Sensor Type - 12Sensor Name - SHTC1 relative humidity sensorSensor Version - 1Sensor Vendor - SensirionMaximum Range - 100.0Minimum Delay - 1000000Power - 0.3Resolution - 0.049.Sensor Type - 13Sensor Name - SHTC1 ambient temperature sensorSensor Version - 1Sensor Vendor - SensirionMaximum Range - 165.0Minimum Delay - 1000000Power - 0.3Resolution - 0.0110.Sensor Type - 15Sensor Name - MPL Game Rotation VectorSensor Version - 1Sensor Vendor - InvensenseMaximum Range - 1200.0Minimum Delay - 10000Power - 6.0Resolution - 0.0611.Sensor Type - 18Sensor Name - SAMSUNG Step Detector SensorSensor Version - 1Sensor Vendor - Samsung Inc.Maximum Range - 1.0Minimum Delay - 0Power - 0.3Resolution - 1.012.Sensor Type - 19Sensor Name - SAMSUNG Step Counter SensorSensor Version - 1Sensor Vendor - Samsung Inc.Maximum Range - 100000.0Minimum Delay - 0Power - 0.3Resolution - 1.013.Sensor Type - 17Sensor Name - SAMSUNG Significant Motion SensorSensor Version - 1Sensor Vendor - Samsung Inc.Maximum Range - 1.0Minimum Delay - 10000Power - 0.3Resolution - 1.014.Sensor Type - 16Sensor Name - MPU6500 Uncalibrated Gyroscope SensorSensor Version - 1Sensor Vendor - InvensenseMaximum Range - 8.726646Minimum Delay - 5000Power - 6.1Resolution - 2.663161E-415.Sensor Type - 65558Sensor Name - Auto Rotation SensorSensor Version - 1Sensor Vendor - Samsung ElectronicsMaximum Range - 255.0Minimum Delay - 0Power - 0.0Resolution - 0.016.Sensor Type - 11Sensor Name - Rotation Vector SensorSensor Version - 3Sensor Vendor - AOSPMaximum Range - 1.0Minimum Delay - 5000Power - 12.35Resolution - 5.9604645E-817.Sensor Type - 9Sensor Name - Gravity SensorSensor Version - 3Sensor Vendor - AOSPMaximum Range - 19.6133Minimum Delay - 5000Power - 12.35Resolution - 5.985504E-418.Sensor Type - 10Sensor Name - Linear Acceleration SensorSensor Version - 3Sensor Vendor - AOSPMaximum Range - 19.6133Minimum Delay - 5000Power - 12.35Resolution - 5.985504E-419.Sensor Type - 3Sensor Name - Orientation SensorSensor Version - 1Sensor Vendor - AOSPMaximum Range - 360.0Minimum Delay - 5000Power - 12.35Resolution - 0.00390625


0 0
原创粉丝点击