Skip to content

Instantly share code, notes, and snippets.

@MrCrambo
Last active July 11, 2020 07:55
Show Gist options
  • Save MrCrambo/46e09f7364e565894296814ea64de12b to your computer and use it in GitHub Desktop.
Save MrCrambo/46e09f7364e565894296814ea64de12b to your computer and use it in GitHub Desktop.
public class NavigineReceiverExample extends BroadcastReceiver {
// here you need to receive some action from intent and depending on this action start service or set repeating alarm
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
try{
if (action.equals("START")) {
PendingIntent pendingIntent = PendingIntent.getBroadcast(
context, 0,
new Intent("WAKE"),
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmService = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
if (alarmService != null)
alarmService.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, 60 * 1000, pendingIntent);
} else if (action.equals("WAKE")) {
context.startService(new Intent(context, NavigineService.class));
}
} catch (Throwable e) {
Logger.d(TAG, 1, Log.getStackTraceString(e));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment