HypoAlarm/HypoAlarm/src/main/java/za/org/treehouse/HypoAlarm/PreAlarmReceiver.java

22 lines
935 B
Java

package za.org.treehouse.HypoAlarm;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public class PreAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
Boolean alarmActive = sharedPref.getBoolean(context.getString(R.string.AlarmActivePref), MainActivity.defaultActive);
if (alarmActive) {
// Create notification
Intent preNotifyIntent = new Intent(context, PreAlarmNotify.class);
// The PreAlarmNotify service can either be stopped by calling CancelAlarmReceiver, or by waiting for AlarmReceiver to run
context.startService(preNotifyIntent);
}
}
}