React-native-firebase: Scheduled notification not shows up

Created on 23 Sep 2018  路  5Comments  路  Source: invertase/react-native-firebase

Issue

I tried to create schedule notification, but nothing shows up, but display notifications works. So I set sheduler for +5sec and it nothing do. No error, no message, nothing. Maybe I missed something?

P.S. with master branch chashing app. It stops

build.gradle implementations

implementation project(':react-native-firebase')
implementation "com.google.android.gms:play-services-base:15.0.1"
implementation "com.google.firebase:firebase-core:16.0.1"
implementation "com.google.firebase:firebase-messaging:17.1.0"

AndroidManifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mydehdeps"
android:versionCode="1"
android:versionName="1.0">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />

<uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="26" />

<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:allowBackup="false"
  android:theme="@style/AppTheme"
>
    <activity
    android:name=".MainActivity"
    android:launchMode="singleTop"
    android:label="@string/app_name"
    android:theme="@style/SplashTheme"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustResize"
    >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
        </intent-filter>
    </activity>

    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

    <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@mipmap/ic_launcher"
    />

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/background"
    />

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/default_notification_channel_id"
    />

    <service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />

    <!-- Schedule notifications -->
    <receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"/>

    <receiver android:enabled="true" android:exported="true"  android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
            <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
            <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>
</application>
</manifest>

Code

import firebase from 'react-native-firebase';


const channel = new firebase.notifications.Android.Channel(
    'dep_time_tracing',
    'Time tracking',
    firebase.notifications.Android.Importance.Max
).setDescription('Hint users how much left time o drive to next dep');
firebase.notifications().android.createChannel(channel);

const localNotification = new firebase.notifications.Notification({
    sound: 'default',
   // show_in_foreground: true,
   // show_in_background: true,
})
    .setNotificationId('hh2')
    .setTitle('bb')
    .setSubtitle('cc')
    .setBody('dssd')
    .setData({
    type: 'start',
})
    .android.setChannelId('dep_time_tracing') // e.g. the id you chose above
    .android.setSmallIcon('ic_launcher') // create this icon in Android Studio
    .android.setColor(COLORS.RED) // you can set a color here
    .android.setPriority(firebase.notifications.Android.Priority.High);

// Schedule the notification for 1 minute in the future
const date = new Date();
date.setSeconds(date.getSeconds() + 5);

firebase.notifications()
    .scheduleNotification(localNotification, {
        fireDate: date.getTime(),
    })
    .catch(err => console.error(err));

Environment

  1. Application Target Platform:

Android(8.0.0) from USB.

  1. Development Operating System:

Ubuntu 18.04

  1. Build Tools:

Android Studio 3.1.4
targetSdkVersion = 26
buildToolsVersion = "27.0.3"
googlePlayServicesVersion = "15.0.1"
supportLibVersion = "26.1.0"
minSdkVersion = 19
compileSdkVersion = 26

  1. React Native version:

0.56.0

  1. React Native Firebase Version:

^4.3.8

  1. Firebase Module:

notification

  1. Are you using typescript?

no


Loving react-native-firebase? Please consider supporting them with any of the below:

Most helpful comment

@esipavicius pls check this link:
https://medium.com/@yangnana11/how-to-set-up-firebase-notification-in-react-native-app-android-only-4920eb875eae
Maybe this can help u.

Hi, thanks!

First time I read, this. But I do not relised it is important to create event listener (firebase.notifications().onNotification) ;/ Maybe it should be updated documentation, because where is not mentioned about this in the https://rnfirebase.io/docs/v5.x.x/notifications/scheduling-notifications ...

Changes: https://github.com/invertase/react-native-firebase-docs/compare/v5.x.x...esipavicius:patch-1

All 5 comments

+1 i have the same issue in Android. Don't know what wrong. :)
I can push a local notification in the simple way, but scheduled not work at all.
Any help?

@esipavicius pls check this link:
https://medium.com/@yangnana11/how-to-set-up-firebase-notification-in-react-native-app-android-only-4920eb875eae
Maybe this can help u.

@esipavicius pls check this link:
https://medium.com/@yangnana11/how-to-set-up-firebase-notification-in-react-native-app-android-only-4920eb875eae
Maybe this can help u.

Hi, thanks!

First time I read, this. But I do not relised it is important to create event listener (firebase.notifications().onNotification) ;/ Maybe it should be updated documentation, because where is not mentioned about this in the https://rnfirebase.io/docs/v5.x.x/notifications/scheduling-notifications ...

Changes: https://github.com/invertase/react-native-firebase-docs/compare/v5.x.x...esipavicius:patch-1

Oh my god, wasted 2, 3 hours on this simple problem. Thank you @esipavicius

Interesting, the patch branch there looks correct but it the alteration does not seem to be integrated into the documentation. @esipavicius do you want to submit that as a PR? It's almost a year old at this point which was before I started helping with the project, maybe there was a reason you didn't propose it but it looks good to me

Was this page helpful?
0 / 5 - 0 ratings