Last active
January 28, 2017 18:37
-
-
Save brendan-fahy/8edee33d17e7edb262595bd93b2b43c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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