-
-
Save jezinka/2ab522971c12447818ff707845fd5442 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
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