简体   繁体   中英

Android Sensor event always return AK8973 3-axis Magnetic field sensor

I tried several time to get Sensor.TYPE_ACCELEROMETER , but it always return AK8973 3-axis Magnetic field sensor. When i shaking mobile device, it always return same AK8973 3-axis Magnetic field sensor. I registered inside resume method, here is code :

boolean supported = mSensorMgr.registerListener(this,
    mSensorMgr.getDefaultSensor(SensorManager.SENSOR_ACCELEROMETER),
    sensorManager.SENSOR_DELAY_GAME);

However, i couldn't get (sensor.getType() == Sensor.TYPE_ACCELEROMETER) inside onSensorChanged(SensorEvent event) method. I couldn't understand why it always return Magnetic field sensor.

Thank you

我解决了问题,我把mSensorMgr.getDefaultSensor(SensorManager.SENSOR_ACCELEROMETER)而不是SensorManager.SENSOR_ACCELEROMETER弄错了,我更改了Sensor.TYPE_ACCELEROMETER,它可以正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM