Google Cardboard VR sensors

Thomas Calc picture Thomas Calc · Nov 7, 2014 · Viewed 7k times · Source

I'm using the Google Cardboard (its HeadTracker class) to detect certain things about device rotation in an AR application. It works very well.

However, on some devices, it doesn't work (nothing happens). I assume this is because they don't have the necessary sensors. My questions:

1) I want to detect at runtime whether the current device supports the HeadTracker, i.e. it has the necessary sensors available. For this, I need to know which sensors are used by HeadTracker, so that I can query if those sensors are present. What are these sensors?

2) Is there a way to specify the necessary sensors in AndroidManifest? As far as I can see, there is no way. Therefore, if a user downloads my app, the app will have to inform the user at runtime that his device is not supported. This is not nice. Any thoughts?

Answer

Daniel Kopitchinski picture Daniel Kopitchinski · Nov 15, 2014

Google cardboard's website has a device compatibility list: It seems somewhat incomplete, so I tried taking a look into Cardboard.jar's source code. HeadTracker.java seems to have the following logic:

SensorManager sensorManager = (SensorManager)HeadTracker.this.mContext.getSystemService("sensor");

for (int sensorType : HeadTracker.INPUT_SENSORS) {
  Sensor sensor = sensorManager.getDefaultSensor(sensorType);
  sensorManager.registerListener(HeadTracker.this.mSensorEventListener, sensor, 0, handler);
}

With INPUT_SENSORS defined in the same file as

{TYPE_ACCELEROMETER, TYPE_GYROSCOPE};

I'm not sure if HeadTracker can work on phones with only one of those sensors. My guess is that both are necessary.

your app can require certain censors in order to run (or even be visible on the android market) with the following lines in your manifest:

<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
<uses-feature android:name="android.hardware.sensor.gyroscope" android:required="true" />

you can also check if the sensors are available to your app at runtime using SensorManager's public Sensor getDefaultSensor (int type) function.