相关传感器
加速传感器: val accelerationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
重力传感器: val gravitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY)
方向传感器: val orientationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION)
陀螺仪传感器: val gyroscopeSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE)
磁场传感器: val magneticFieldSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)
线性加速度传感器: val linearAccelerationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION)
环境温度传感器: val ambientTemperatureSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE)
事例
val mSensorManager = getSystemService(SENSOR_SERVICE) as SensorManager
//重力加速传感器
val accelerationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
mSensorEventListener = object : SensorEventListener {
override fun onSensorChanged(event: SensorEvent) {
val x = event.values[0]
val y = event.values[1]
val z = event.values[2]
}
override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {
}
}
mSensorManager.registerListener(mSensorEventListener, accelerationSensor, SensorManager.SENSOR_DELAY_NORMAL)
标签:val,mSensorManager,TYPE,getDefaultSensor,传感器,Android,Sensor
From: https://www.cnblogs.com/alasola/p/16718300.html