Android: Trying to get notifications to work in Android 8.x

pull/1061/head
Laurent Cozic 2018-12-20 14:52:56 +01:00
parent 685845e097
commit 5565538b80
3 changed files with 12 additions and 2 deletions

View File

@ -48,6 +48,9 @@
<meta-data <meta-data
android:name="com.google.firebase.messaging.default_notification_icon" android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_stat_access_alarm" /> android:resource="@drawable/ic_stat_access_alarm" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
<receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"/> <receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"/>
<receiver android:enabled="true" android:exported="true" android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver"> <receiver android:enabled="true" android:exported="true" android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver">
<intent-filter> <intent-filter>

View File

@ -1,3 +1,4 @@
<resources> <resources>
<string name="app_name">Joplin</string> <string name="app_name">Joplin</string>
<string name="default_notification_channel_id">net.cozic.joplin.notification</string>
</resources> </resources>

View File

@ -2,6 +2,12 @@ import firebase from 'react-native-firebase';
class AlarmServiceDriver { 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() { hasPersistentNotifications() {
return true; return true;
} }
@ -23,10 +29,10 @@ class AlarmServiceDriver {
firebaseNotification.setNotificationId(this.firebaseNotificationId_(notification.id)); firebaseNotification.setNotificationId(this.firebaseNotificationId_(notification.id));
firebaseNotification.setTitle(notification.title) firebaseNotification.setTitle(notification.title)
if ('body' in notification) firebaseNotification.body = notification.body; 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'); firebaseNotification.android.setSmallIcon('ic_stat_access_alarm');
firebase.notifications().scheduleNotification(firebaseNotification, { await firebase.notifications().scheduleNotification(firebaseNotification, {
fireDate: notification.date.getTime(), fireDate: notification.date.getTime(),
}); });
} }