From 328f77d54c2b0fec062a49247c18b3f8f5a5cfff Mon Sep 17 00:00:00 2001 From: tom79 Date: Sun, 22 Oct 2017 11:55:49 +0200 Subject: [PATCH] Fixes notifications on Android O --- .../java/fr/gouv/etalab/mastodon/helper/Helper.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 48bdaabb9..4cfe09474 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -18,6 +18,8 @@ package fr.gouv.etalab.mastodon.helper; import android.app.Activity; +import android.app.NotificationChannel; +import android.app.NotificationManager; import android.graphics.Color; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; @@ -612,7 +614,14 @@ public class Helper { intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP); RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // build notification - NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) + String channelId = "channel_"+ String.valueOf(notificationId); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(channelId, title, NotificationManager.IMPORTANCE_DEFAULT); + NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.createNotificationChannel(channel); + } + + NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId) .setSmallIcon(R.drawable.notification_icon) .setTicker(message) .setWhen(System.currentTimeMillis())