Stay organized with collections
Save and categorize content based on your preferences.
TriggerEventListener
public
abstract
class
TriggerEventListener
extends Object
This class is the listener used to handle Trigger Sensors.
Trigger Sensors are sensors that trigger an event and are automatically
disabled. Sensor.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
Context.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 methods |
abstract
void
|
onTrigger(TriggerEvent event)
The method that will be called when the sensor
is triggered.
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait(long timeoutMillis, int nanos)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait(long timeoutMillis)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait()
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted.
|
|
Public constructors
TriggerEventListener
public TriggerEventListener ()
Public methods
onTrigger
public abstract void onTrigger (TriggerEvent event)
The method that will be called when the sensor
is triggered. Override this method in your implementation
of this class.
Parameters |
event |
TriggerEvent : The details of the event. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# TriggerEventListener\n\nAdded in [API level 18](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Ctors](#pubctors) \\| [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nTriggerEventListener\n====================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/hardware/TriggerEventListener \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\n\n\nabstract\nclass\nTriggerEventListener\n`\n\n\n`\n\nextends `[Object](/reference/java/lang/Object)`\n\n\n`\n\n`\n\n\n`\n\n|---|---------------------------------------|\n| [java.lang.Object](/reference/java/lang/Object) ||\n| ↳ | android.hardware.TriggerEventListener |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nThis class is the listener used to handle Trigger Sensors.\nTrigger Sensors are sensors that trigger an event and are automatically\ndisabled. [Sensor.TYPE_SIGNIFICANT_MOTION](/reference/android/hardware/Sensor#TYPE_SIGNIFICANT_MOTION) is one such example.\n\n\n[SensorManager](/reference/android/hardware/SensorManager) lets you access the device's [sensors](/reference/android/hardware/Sensor). Get an instance of [SensorManager](/reference/android/hardware/SensorManager) by calling\n[Context.getSystemService()](/reference/android/content/Context#getSystemService(java.lang.String)) with the argument\n[Context.SENSOR_SERVICE](/reference/android/content/Context#SENSOR_SERVICE).\n\nHere's an example setup for a TriggerEventListener:\n\n```\n class TriggerListener extends TriggerEventListener {\n public void onTrigger(TriggerEvent event) {\n // Do Work.\n\n // As it is a one shot sensor, it will be canceled automatically.\n // SensorManager.requestTriggerSensor(this, mSigMotion); needs to\n // be called again, if needed.\n }\n }\n public class SensorActivity extends Activity {\n private final SensorManager mSensorManager;\n private final Sensor mSigMotion;\n private final TriggerEventListener mListener = new TriggerEventListener();\n\n public SensorActivity() {\n mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);\n mSigMotion = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);\n }\n\n protected void onResume() {\n super.onResume();\n mSensorManager.requestTriggerSensor(mListener, mSigMotion);\n }\n\n protected void onPause() {\n super.onPause();\n // Call disable to ensure that the trigger request has been canceled.\n mSensorManager.cancelTriggerSensor(mListener, mSigMotion);\n }\n\n }\n \n```\n\n\u003cbr /\u003e\n\n**See also:**\n\n- [TriggerEvent](/reference/android/hardware/TriggerEvent)\n- [Sensor](/reference/android/hardware/Sensor)\n\nSummary\n-------\n\n| ### Public constructors ||\n|---------------------------------------------------------------------------------------------------------|---|\n| ` `[TriggerEventListener](/reference/android/hardware/TriggerEventListener#TriggerEventListener())`() ` |\n\n| ### Public methods ||\n|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[onTrigger](/reference/android/hardware/TriggerEventListener#onTrigger(android.hardware.TriggerEvent))`(`[TriggerEvent](/reference/android/hardware/TriggerEvent)` event) ` The method that will be called when the sensor is triggered. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` `[java.lang.Object](/reference/java/lang/Object)` ` |---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](/reference/java/lang/Object) | ` `[clone](/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object. | | ` boolean` | ` `[equals](/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](/reference/java/lang/Object)` obj) ` Indicates whether some other object is \"equal to\" this one. | | ` void` | ` `[finalize](/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final `[Class](/reference/java/lang/Class)`\u003c?\u003e` | ` `[getClass](/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this `Object`. | | ` int` | ` `[hashCode](/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object. | | ` final void` | ` `[notify](/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` `[notifyAll](/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor. | | ` `[String](/reference/java/lang/String) | ` `[toString](/reference/java/lang/Object#toString())`() ` Returns a string representation of the object. | | ` final void` | ` `[wait](/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` `[wait](/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` `[wait](/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||\n\nPublic constructors\n-------------------\n\n### TriggerEventListener\n\n```\npublic TriggerEventListener ()\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nPublic methods\n--------------\n\n### onTrigger\n\nAdded in [API level 18](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onTrigger (TriggerEvent event)\n```\n\nThe method that will be called when the sensor\nis triggered. Override this method in your implementation\nof this class.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------|--------------------------------------------------|\n| `event` | `TriggerEvent`: The details of the event. \u003cbr /\u003e |"]]