These are the ingredients you need for you recipe:
An Intent
that targets your BroadcastReceiver
:
Intent intent = new Intent(context, YourBroadCastReceiver.class);
A PendingIntent
that gets triggered by the AlarmManager
and fires your already defined Intent
:
PendingIntent pIntent = PendingIntent.getBroadcast(context, requestCode, intent, flags);
The AlarmManager
that periodically activates your PendingIntent
:
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, intervalMillis, pIntent);
The BroadCastReceiver
that handles the event:
@Override
protected void handleReceive(Context context, Intent intent) {
// handle GPS
}