Example usage for android.hardware TriggerEventListener TriggerEventListener

List of usage examples for android.hardware TriggerEventListener TriggerEventListener

Introduction

In this page you can find the example usage for android.hardware TriggerEventListener TriggerEventListener.

Prototype

TriggerEventListener

Source Link

Usage

From source file:org.mozilla.mozstumbler.service.stumblerthread.motiondetection.SignificantMotionSensor.java

@Override
public void start() {
    mStopSignificantMotionSensor = false;

    if (Build.VERSION.SDK_INT >= 18) {
        final TriggerEventListener tr = new TriggerEventListener() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
            @Override//w w w.j  av a2 s . c o  m
            public void onTrigger(TriggerEvent event) {
                if (mStopSignificantMotionSensor) {
                    return;
                }
                AppGlobals.guiLogInfo("Major motion detected.");

                LocalBroadcastManager localBroadcastManager = null;

                if (mAppContext == null) {
                    NullPointerException npe = new NullPointerException("mAppContext == null");
                    ACRA.getErrorReporter().handleException(npe);
                    return;
                }
                try {
                    localBroadcastManager = LocalBroadcastManager.getInstance(mAppContext);
                } catch (NullPointerException npe) {
                    String ctxName = "NULL";
                    if (mAppContext != null) {
                        ctxName = mAppContext.toString();
                    }
                    ACRA.getErrorReporter().putCustomData("mAppContext", ctxName);

                    // Send the report (Stack trace will say "Requested by Developer"
                    // That should set apart manual reports from actual crashes
                    ACRA.getErrorReporter().handleException(npe);
                    return;
                }

                if (localBroadcastManager == null) {
                    NullPointerException npe = new NullPointerException("localBroadcastManager == null");
                    // Send the report (Stack trace will say "Requested by Developer"
                    // That should set apart manual reports from actual crashes
                    ACRA.getErrorReporter().handleException(npe);
                    return;
                }

                localBroadcastManager.sendBroadcastSync(new Intent(MotionSensor.ACTION_USER_MOTION_DETECTED));
                mSensorManager.requestTriggerSensor(this, mSignificantMotionSensor);
            }
        };

        mSensorManager.requestTriggerSensor(tr, mSignificantMotionSensor);
    }
}