package com.example.stimulusStrategy; import android.app.Notification; import android.app.Service; import android.content.Context; import android.content.Intent; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.IBinder; import android.support.annotation.Nullable; /** * Created by pharmacy on 17/01/2018. */ public class LinearAcceleration extends Service implements StimulusStrategy, SensorEventListener { private SensorManager mSensorManager; private Sensor laccl; private final float calibrationValue = 1; @Override public void onCreate(){ mSensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE); laccl = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION); } public void monitor() { Intent i = new Intent(this, Notification.class); this.sendBroadcast(i); } @Nullable @Override public IBinder onBind(Intent intent) { return null; } @Override public void onSensorChanged(SensorEvent sensorEvent) { for(float value: sensorEvent.values){ if(value < calibrationValue){ return; } } monitor(); } @Override public void onAccuracyChanged(Sensor sensor, int i) { } }