SmartEyeglass HeroSmartEyeglass Hero

Develop customized AR solutions

Sony’s augmented reality SmartEyeglass* is developed for increasing business productivity and reducing errors. Transform the way you work by enhancing reality with information and graphics.

*Discontinued model.

Sensor data

This guide explains how to access sensor data from your SmartEyeglass app.

Data from device sensors, such as the light sensor and accelerometer, is available to you through the Sensor API defined by AccessorySensorManager in the SmartExtensionsUtils library. The methods in this class allow you to manage sensors of different types, capture sensor events, and query various parameters for each type of sensor.

For specific information on the sensors that SmartEyeglass supports, see the Hardware overview page.

The basics

To get started working with sensor data, set up a project using the HelloSensors sample as a base; see more about creating SmartEyeglass projects in the How to create your first SmartEyeglass project tutorial.

You will use the Sensor API for listening to sensor data, so the class that extends RegistrationInformation must get the version that supports this functionality:

  1. @Override
  2. public int getRequiredSensorApiVersion() {
  3. return 1;
  4. }

The HelloSensors project does this. If you don’t use this sample as a base, make sure you do the same.

Select sensors to listen to

Instantiate an AccessorySensorManager member, and use it to start listening to the sensors you are interested in. See the API references for a complete list of sensors that are available. You can also check at run time to see if a particular sensor is available on the Sony accessory that your extension is currently running on:

  1. List mSensors = new ArrayList();
  2. AccessorySensorManager manager = new AccessorySensorManager(context, hostAppPackageName);
  4. // Add accelerometer, if supported by the host application.
  5. if (DeviceInfoHelper.isSensorSupported(context, hostAppPackageName,
  6. SensorTypeValue.ACCELEROMETER)) {
  7. mSensors.add(manager.getSensor(SensorTypeValue.ACCELEROMETER));
  8. }
  10. // Add magnetic field sensor, if supported by the host application.
  11. if (DeviceInfoHelper.isSensorSupported(context, hostAppPackageName,
  12. SensorTypeValue.MAGNETIC_FIELD)) {
  13. mSensors.add(manager.getSensor(SensorTypeValue.MAGNETIC_FIELD));
  14. }

Register a sensor listener

To respond to sensor input, you must register event listeners for the events of interest. You can create either a fixed- rate listener that polls at specified intervals, or an interrupt listener:

  1. //Fixed-rate listener
  2. sensor.registerFixedRateListener(mListener, Sensor.SensorRates.SENSOR_DELAY_UI);
  3. //Interrupt listener
  4. sensor.registerInterruptListener(mListener);

An event listener can be active for only one sensor at a time. If you have been listening to events for one sensor and wish to switch to another sensor, you must unregister the current listener and register anew listener. See the sample for an example of how to switch sensor listeners.

Get data values

In your listener, override the onSensorEvent() method in order to access the returned AccessorySensorEvent object that contains the sensor data. For example:

  1. private final AccessorySensorEventListener mListener = new AccessorySensorEventListener() {
  2. @Override
  3. public void onSensorEvent(AccessorySensorEvent sensorEvent) {
  4. float[] values = sensorEvent.getSensorValues();
  5. TextView xView = (TextView)sensorLayout.findViewById(;
  6. TextView yView = (TextView)sensorLayout.findViewById(;
  7. TextView zView = (TextView)sensorLayout.findViewById(;
  9. // Show values with one decimal.
  10. xView.setText(String.format("%.1f", values[0]));
  11. yView.setText(String.format("%.1f", values[1]));
  12. zView.setText(String.format("%.1f", values[2]));
  13. }
  14. };

Rotation vector data

The sensor data values returned for the rotation vector are reversed in direction from the Android standard. The axis values represent rotations toward these directions:

  SmartEyeglass Android X-axis points North points East Y-axis points East points North Z-axis points toward ground points toward sky

For both SmartEyeglass and standard Android, the Z-axis value is perpendicular to the ground plane.

Rotation vector coordinate directions.

For more information, see the sensor documentation on Google’s Android developer website:

• Learn about motion sensors. • Check out Google’s sensor overview.

Learn from the code example

For the full code example of how to get sensor data, see the HelloSensors sample project in the /samples folder of the SmartEyeglass SDK.