Android Advanced Sensor Usage

In the previous article, We learned about the basic properties of the SensorManager, SensorEventListner and Sensor objects along with their usage. In this article we will look closer at some of the more advanced sensor properties and processing sensor data.

 
Trigger Events
In addition to the previously discussed SensorEventListener, Android 4.3 introduced an additional mechanism for receiving sensor data: the TriggerEventListener. TriggerEventListener is mainly used for a special sensor type called significant motion. The signification motion sensor is a software sensor derived from hardware sensors present on the device. The only allowed value the sensor can return is 1.0. So what does this sensor actually do? It detects when the Android device has a sudden motion or jerk.  Unlike SensorEventListener, the TriggerEventListener is a one shot: it is automatically canceled after the trigger.  At the Java level, one major difference between the two listener types is that TriggerEventListener is a class not an interface, so we need to extend and implement the overridden method onTrigger().  The onTrigger() method receives a TriggerEvent object as a parameter. The TriggerEvent class is nearly the same as the SensorEvent class, except it doesn’t have onAccuracyChanged() method.  This is because the trigger event is only fired a single time, after that it will unregister itself.  Here’s a brief example of using TriggerEventListener:

 
public class TriggerListener extends TriggerEventListener {
private TextView mText;

public TriggerListener(TextView textView){
this.mText = textView;
}

@Override
public void onTrigger(TriggerEvent event) {
Log.i(“TriggerListener”, “Name:” + event.sensor.getName());
Log.i(“TriggerListener”,”Type:” + event.sensor.getType());

mText.setText(“Name: […]

Android Sensor Support: Tap into the Device’s Environment

“A sensor is a device that detects events or changes in quantities and provides a corresponding output, generally as an electrical or optical signal; for example, a thermocouple converts temperature to an output voltage.” – Wikipedia

Introduction
Before we jump into the Android Sensor Framework, let’s take a brief step back and examine some basic concepts with regards to sensors. As humans, we have five senses: sight, hearing, taste, smell and touch. These give us the ability to receive input of various kinds to understand and analyze the world around us. The same principle applies to a mobile device. Mobile devices have lots of sensors which allow them to understand and analyze the world around them. However, unlike human senses, smartphones have many more sensor types available. There are over three hundred different types of sensors which exist for different domains and industries. Smartphones today contain just the bare minimum of these various sensors. In the near future mobile devices will likely have many more sensors built in., In fact, few companies like Samsung have started mounting more and more sensors in the device. For example, the Samsung Galaxy S5 contains ten different sensors. Sensors are becoming an essential part of the mobile device. If you ask me what the major differences are between a feature phone and smartphone, my first response would be “sensors.” Sensors are one of the main features that distinguishes a feature phone and a smartphone.  One way to interpret the “smart” in smartphone would be:

 

S = Sensors
M = Multi-Tasking
A = Applications
R = Real-Time (almost)
T = Touch Screen

 
Android Sensor Concepts
Android devices have many sensors, such as an accelerometer, a light sensor, or a proximity sensor. Availability of sensors are different per model […]