Sony Get Your Apps To Work With The Xperia Go Pressure Sensor Tutorial

Sony Get your apps to work with the Xperia go pressure sensor tutorialWe just announced the Sony Xperia™ go, which comes with equipped with a pressure sensor, which enables you as a developer to create barometric, altitude or speed-related apps by accessing it through the Android sensor API. In this article, we're highlighting information on how you can develop apps that work with the pressure sensor in Xperia™ go, as well as Xperia™ active as the sensor is accessed through the same API.

Read on to get a code example and instructions on how to create a simple app that can read data from the pressure sensor.

Awhile back, we published a barometric sensor app and code sample for Xperia active to show you how to get your apps to work with this unique feature. With the recently announced Xperia™ go, you now have another Xperia™ smartphone that can also use any existing pressure sensor-related apps you've created for Xperia™ active. The possibilities for developing apps for the sensor are endless, as you'll be able to generate data for apps such as weather logs, barometric apps, or altitude-related uses.

Set up the basics

It's pretty straightforward to make use of the API. You should first learn the basics on creating a simple app that reads data from the pressure sensor and displays it in a simple text view. This starts with creating an activity, to have something to display. The activity should implement the sensor listener interface. Use the OnCreate() method) to have the app connect to the sensor itself, through the normal sensor interface. Then, your app needs to register itself as a SensorEventListener, which can be done by overwriting the OnResume method. Finally, your application will need to implement the SensorEventListener interface methods.

Add more features

Going beyond the basics, you might also consider another, potentially more useful approach – letting a service log the data from the pressure sensor to a content provider. To build a logger system, begin by implementing the actual data as a simple class, which starts a separate thread by implementing the Runnable interface. This is done in order to be able to receive a number of callbacks to the SensorListener. The data collecting class is initialised and run from a service, with a median value stored in a content provider. The content provider is called from a utility class.

Verify your app

The best way to test your app that uses the pressure sensor is to use it on an actual Xperia™ go or Xperia™ active. Or you could borrow and test an Xperia™ smartphone from our Device Loaner Program. Otherwise, there is a way to tweak your code in order to verify that your application is working properly. Normally your typical app consists of at least two parts. One part that collects data, and one logical part that displays the data. In this case, it is tricky to verify the collection of data, but you can verify how the data is displayed. What you can do, is to feed the data using another sensor, perhaps the accelerometer, and adjust the values to the appropriate air pressure. You can then use this data as input. Since the accelerometer tends to give values between +10 to -10, it is roughly a matter of adding 1013 to the sensor value to get appropriate values.