Most visited

Recently visited

Added in API level 18

TriggerEventListener

public abstract class TriggerEventListener
extends Object

java.lang.Object
   ↳ android.hardware.TriggerEventListener


这个类是用来处理触发传感器的监听器。 触发传感器是触发事件并自动禁用的传感器。 TYPE_SIGNIFICANT_MOTION就是这样一个例子。

SensorManager可让您访问设备的sensors 获取的实例SensorManager通过调用Context.getSystemService()的说法SENSOR_SERVICE

以下是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)

传感器被触发时将调用的方法。

Inherited methods

From class java.lang.Object

Public constructors

TriggerEventListener

Added in API level 18
TriggerEventListener ()

Public methods

onTrigger

Added in API level 18
void onTrigger (TriggerEvent event)

传感器被触发时将调用的方法。 在您实现此类时覆盖此方法。

Parameters
event TriggerEvent: The details of the event.

Hooray!