From 5565538b804de6df7cf4956ed99ba55c4c1b707e Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 20 Dec 2018 14:52:56 +0100 Subject: [PATCH] Android: Trying to get notifications to work in Android 8.x --- .../android/app/src/main/AndroidManifest.xml | 3 +++ .../android/app/src/main/res/values/strings.xml | 1 + .../lib/services/AlarmServiceDriver.android.js | 10 ++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ReactNativeClient/android/app/src/main/AndroidManifest.xml b/ReactNativeClient/android/app/src/main/AndroidManifest.xml index 582c2ee8b0..8b0032397b 100644 --- a/ReactNativeClient/android/app/src/main/AndroidManifest.xml +++ b/ReactNativeClient/android/app/src/main/AndroidManifest.xml @@ -48,6 +48,9 @@ + diff --git a/ReactNativeClient/android/app/src/main/res/values/strings.xml b/ReactNativeClient/android/app/src/main/res/values/strings.xml index 4c3fb50cb6..f89aea2b78 100644 --- a/ReactNativeClient/android/app/src/main/res/values/strings.xml +++ b/ReactNativeClient/android/app/src/main/res/values/strings.xml @@ -1,3 +1,4 @@ Joplin + net.cozic.joplin.notification diff --git a/ReactNativeClient/lib/services/AlarmServiceDriver.android.js b/ReactNativeClient/lib/services/AlarmServiceDriver.android.js index 3de7ce257e..d29a56a43c 100644 --- a/ReactNativeClient/lib/services/AlarmServiceDriver.android.js +++ b/ReactNativeClient/lib/services/AlarmServiceDriver.android.js @@ -2,6 +2,12 @@ import firebase from 'react-native-firebase'; class AlarmServiceDriver { + constructor() { + this.channel_ = new firebase.notifications.Android.Channel('net.cozic.joplin.notification', 'Joplin Alarm',firebase.notifications.Android.Importance.Max) + .setDescription('Displays a notification for alarms associated with to-dos.'); + firebase.notifications().android.createChannel(this.channel_); + } + hasPersistentNotifications() { return true; } @@ -23,10 +29,10 @@ class AlarmServiceDriver { firebaseNotification.setNotificationId(this.firebaseNotificationId_(notification.id)); firebaseNotification.setTitle(notification.title) if ('body' in notification) firebaseNotification.body = notification.body; - firebaseNotification.android.setChannelId('com.google.firebase.messaging.default_notification_channel_id'); + firebaseNotification.android.setChannelId('net.cozic.joplin.notification'); firebaseNotification.android.setSmallIcon('ic_stat_access_alarm'); - firebase.notifications().scheduleNotification(firebaseNotification, { + await firebase.notifications().scheduleNotification(firebaseNotification, { fireDate: notification.date.getTime(), }); }