23 lines
1014 B
Java
23 lines
1014 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), true);
|
|
String alarmTimeStr = sharedPref.getString(context.getString(R.string.AlarmTimePref), null);
|
|
|
|
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);
|
|
}
|
|
}
|
|
} |