首页 > 代码库 > android获取传感器列表
android获取传感器列表
本文介绍如何获取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 { @Override protected 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()); } @Override public 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 - 1 Sensor Name - MPU6500 Acceleration Sensor Sensor Version - 1 Sensor Vendor - Invensense Maximum Range - 19.6133 Minimum Delay - 5000 Power - 0.25 Resolution - 5.985504E-4 2. Sensor Type - 2 Sensor Name - YAS532 Magnetic Sensor Sensor Version - 1 Sensor Vendor - Yamaha Corporation Maximum Range - 1200.0 Minimum Delay - 10000 Power - 6.0 Resolution - 0.06 3. Sensor Type - 14 Sensor Name - YAS532 Uncalibrated Magnetic Sensor Sensor Version - 1 Sensor Vendor - Yamaha Corporation Maximum Range - 1200.0 Minimum Delay - 10000 Power - 6.0 Resolution - 0.06 4. Sensor Type - 4 Sensor Name - MPU6500 Gyroscope Sensor Sensor Version - 1 Sensor Vendor - Invensense Maximum Range - 8.726646 Minimum Delay - 5000 Power - 6.1 Resolution - 2.663161E-4 5. Sensor Type - 6 Sensor Name - Barometer Sensor Sensor Version - 1 Sensor Vendor - BOSCH Maximum Range - 1013.25 Minimum Delay - 66700 Power - 1.0 Resolution - 1.0 6. Sensor Type - 8 Sensor Name - MAX88921 Proximity Sensor Sensor Version - 1 Sensor Vendor - MAXIM, Inc. Maximum Range - 8.0 Minimum Delay - 0 Power - 0.75 Resolution - 8.0 7. Sensor Type - 5 Sensor Name - MAX88921 RGB Sensor Sensor Version - 1 Sensor Vendor - MAXIM, Inc. Maximum Range - 60000.0 Minimum Delay - 200000 Power - 0.75 Resolution - 1.0 8. Sensor Type - 12 Sensor Name - SHTC1 relative humidity sensor Sensor Version - 1 Sensor Vendor - Sensirion Maximum Range - 100.0 Minimum Delay - 1000000 Power - 0.3 Resolution - 0.04 9. Sensor Type - 13 Sensor Name - SHTC1 ambient temperature sensor Sensor Version - 1 Sensor Vendor - Sensirion Maximum Range - 165.0 Minimum Delay - 1000000 Power - 0.3 Resolution - 0.01 10. Sensor Type - 15 Sensor Name - MPL Game Rotation Vector Sensor Version - 1 Sensor Vendor - Invensense Maximum Range - 1200.0 Minimum Delay - 10000 Power - 6.0 Resolution - 0.06 11. Sensor Type - 18 Sensor Name - SAMSUNG Step Detector Sensor Sensor Version - 1 Sensor Vendor - Samsung Inc. Maximum Range - 1.0 Minimum Delay - 0 Power - 0.3 Resolution - 1.0 12. Sensor Type - 19 Sensor Name - SAMSUNG Step Counter Sensor Sensor Version - 1 Sensor Vendor - Samsung Inc. Maximum Range - 100000.0 Minimum Delay - 0 Power - 0.3 Resolution - 1.0 13. Sensor Type - 17 Sensor Name - SAMSUNG Significant Motion Sensor Sensor Version - 1 Sensor Vendor - Samsung Inc. Maximum Range - 1.0 Minimum Delay - 10000 Power - 0.3 Resolution - 1.0 14. Sensor Type - 16 Sensor Name - MPU6500 Uncalibrated Gyroscope Sensor Sensor Version - 1 Sensor Vendor - Invensense Maximum Range - 8.726646 Minimum Delay - 5000 Power - 6.1 Resolution - 2.663161E-4 15. Sensor Type - 65558 Sensor Name - Auto Rotation Sensor Sensor Version - 1 Sensor Vendor - Samsung Electronics Maximum Range - 255.0 Minimum Delay - 0 Power - 0.0 Resolution - 0.0 16. Sensor Type - 11 Sensor Name - Rotation Vector Sensor Sensor Version - 3 Sensor Vendor - AOSP Maximum Range - 1.0 Minimum Delay - 5000 Power - 12.35 Resolution - 5.9604645E-8 17. Sensor Type - 9 Sensor Name - Gravity Sensor Sensor Version - 3 Sensor Vendor - AOSP Maximum Range - 19.6133 Minimum Delay - 5000 Power - 12.35 Resolution - 5.985504E-4 18. Sensor Type - 10 Sensor Name - Linear Acceleration Sensor Sensor Version - 3 Sensor Vendor - AOSP Maximum Range - 19.6133 Minimum Delay - 5000 Power - 12.35 Resolution - 5.985504E-4 19. Sensor Type - 3 Sensor Name - Orientation Sensor Sensor Version - 1 Sensor Vendor - AOSP Maximum Range - 360.0 Minimum Delay - 5000 Power - 12.35 Resolution - 0.00390625
android获取传感器列表
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。