Skip to content

Instantly share code, notes, and snippets.

@brendan-fahy
Last active January 28, 2017 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendan-fahy/8edee33d17e7edb262595bd93b2b43c8 to your computer and use it in GitHub Desktop.
Save brendan-fahy/8edee33d17e7edb262595bd93b2b43c8 to your computer and use it in GitHub Desktop.
val alarmIntent = Intent(context, AlarmReceiver::class.java)
val pendingIntent = PendingIntent.getBroadcast(context, JOB_ID, alarmIntent, 0)
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
if (batteryStatus.shouldShowNotification()) {
Log.d(TAG, "onReceive: device is charging or unknown, scheduling job.")
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, JOB_INTERVAL,
pendingIntent)
} else if (batteryStatus.shouldClearNotification()) {
Log.d(TAG, "onReceive: device has been disconnected, cancelling all jobs.")
alarmManager.cancel(pendingIntent)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment