Skip to content

Instantly share code, notes, and snippets.

@jezinka
Created August 12, 2018 13:02
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 jezinka/2ab522971c12447818ff707845fd5442 to your computer and use it in GitHub Desktop.
Save jezinka/2ab522971c12447818ff707845fd5442 to your computer and use it in GitHub Desktop.
private void checkBatteryState(List<Sensor> sensors) {
for (Sensor sensor : sensors) {
if (sensor.batteryNeedRecharge()) {
sendNotification(sensor);
}
}
}
private void sendNotification(Sensor sensor) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_battery)
.setContentTitle(getString(R.string.notification_title))
.setContentText(sensor.getLabel() + getString(R.string.notification_text))
.setAutoCancel(true)
.setOngoing(false);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify((int) sensor.getId(), mBuilder.build());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment