package org.deke.risk.riskahead.helper;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.format.DateUtils;
import android.util.Log;


public class RABroadcastReceiver extends BroadcastReceiver {
    private final static String TAG = RABroadcastReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Log.d(TAG, "BroadcastReceiver received intent");

            Intent wtdSServiceIntent = new Intent(context, NotificationService.class);
            PendingIntent wtdSServicePendingIntent = PendingIntent.
                    getService(context, 0, wtdSServiceIntent, 0);

            long interval = DateUtils.MINUTE_IN_MILLIS * 2;
            long firstStart = System.currentTimeMillis() + interval;

            AlarmManager am = (AlarmManager) context
                    .getSystemService(Context.ALARM_SERVICE);
            am.setInexactRepeating(AlarmManager.RTC, firstStart,
                    interval, wtdSServicePendingIntent);

            Log.v("WhatTheDroidService", "AlarmManager gesetzt");
        }
    }
}
