AppleGrew
AppleGrew

Reputation: 9570

Why do I get null for Sensor.TYPE_ROTATION_VECTOR and Sensor.TYPE_GAME_ROTATION_VECTOR?

I have a Yureka phone, and from its specs I can see that it has at least an accelerometer and a gyroscope.

What I found from the net is that TYPE_ROTATION_VECTOR needs accelerometer, gyroscope and magnetometer. Since I do not have magnetometer, maybe because of that I am unable to get this sensor.

However, from docs it looks like TYPE_GAME_ROTATION_VECTOR does not need magnetometer, then why am I also not getting this sensor?

I am trying to use this sensor to measure the tilt angle, with respect to ground, of the phone screen when the user is trying to hold it flat on his hands.

Upvotes: 1

Views: 1282

Answers (1)

Anhong
Anhong

Reputation: 232

First, you can try to use the code below to print out the information of all the sensors on your device. If the sensor is not printed out, it's not available.

List<Sensor> deviceSensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);
for(int i=0; i<gravSensors.size(); i++) {
    // print out sensors information
}

Then, even if you have an accelerometer and a gyroscope, the TYPE_GAME_ROTATION_VECTOR might still not be supported. That's because it's a software sensor, and is derived from the data from other sensors by the Android system. There might be other factors that decides the availability of the software sensor, e.g. frequency, energy consumption, reliability. In that way, you might need to derive the other values yourself using the raw data you can get from the sensors.

Hope this helps!

Upvotes: 1

Related Questions