to top
Android APIs
public abstract class

TriggerEventListener

extends Object
java.lang.Object
   ↳ android.hardware.TriggerEventListener

Class Overview

This class is the listener used to handle Trigger Sensors. Trigger Sensors are sensors that trigger an event and are automatically disabled. TYPE_SIGNIFICANT_MOTION is one such example.

SensorManager lets you access the device's sensors. Get an instance of SensorManager by calling Context.getSystemService() with the argument SENSOR_SERVICE.

Here's an example setup for a TriggerEventListener:

 class TriggerListener extends TriggerEventListener {
     public void onTrigger(TriggerEvent event) {
          // Do Work.

     // As it is a one shot sensor, it will be canceled automatically.
     // SensorManager.requestTriggerSensor(this, mSigMotion); needs to
     // be called again, if needed.
     }
 }
 public class SensorActivity extends Activity {
     private final SensorManager mSensorManager;
     private final Sensor mSigMotion;
     private final TriggerEventListener mListener = new TriggerEventListener();

     public SensorActivity() {
         mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
         mSigMotion = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
     }

     protected void onResume() {
         super.onResume();
         mSensorManager.requestTriggerSensor(mListener, mSigMotion);
     }

     protected void onPause() {
         super.onPause();
         // Call disable to ensure that the trigger request has been canceled.
         mSensorManager.cancelTriggerSensor(mListener, mSigMotion);
     }

 }
 

Summary

Public Constructors
TriggerEventListener()
Public Methods
abstract void onTrigger(TriggerEvent event)
The method that will be called when the sensor is triggered.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public TriggerEventListener ()

Added in API level 18

Public Methods

public abstract void onTrigger (TriggerEvent event)

Added in API level 18

The method that will be called when the sensor is triggered. Override this method in your implementation of this class.

Parameters
event The details of the event.