React-native-fcm: scheduleLocalNotification not working on Android

Created on 1 Sep 2017  路  4Comments  路  Source: evollu/react-native-fcm

@evollu
I am able to send local notifications with _presentLocalNotification_ but _scheduleLocalNotification_ doesn't seem to work on Android. On iOS everything works fine.

I'm using RN 0.45.1 with react-native-fcm 6.2.3.

I've gone through the Android configuration many times and can't find what's wrong.
I schedule the notification with (like the docs almost):
```
FCM.scheduleLocalNotification({
fire_date: new Date().getTime(),
id: uuid(),
title: "Title of the notification"
body: "This is a random body",
show_in_foreground: true,
})
````
I don't receive any notification (app both in foreground or background). Any ideas would be welcome, I tried to update react-native-fcm to "9.1.0" but now I get "this._nativeModule.addListener is not a function" on iOS and still trying to fix it...

Most helpful comment

I copied it from the docs in my debugging spree, but thanks to your comment i found the problem:
ISO Strings (2013-02-04T22:44:30.652Z) for the "fire_date" parameter work on iOS but not on Android where you need a UnixTimestamp apparently:

Using moment:
fire_date: moment().add(30, 's').toIsoString() //doesn't work on Android
fire_date: moment().add(30, 's').valueOf() //works

Thanks for the quick reply!

All 4 comments

fire_date: new Date().getTime() means it is in the past. try add 5000 ms?

I copied it from the docs in my debugging spree, but thanks to your comment i found the problem:
ISO Strings (2013-02-04T22:44:30.652Z) for the "fire_date" parameter work on iOS but not on Android where you need a UnixTimestamp apparently:

Using moment:
fire_date: moment().add(30, 's').toIsoString() //doesn't work on Android
fire_date: moment().add(30, 's').valueOf() //works

Thanks for the quick reply!

@xavieramoros I have add moment js and use your syntax moment().add(30, 's').valueOf() but it's still not works for me

and console.log of moment js and Date give same output

@buncismamen please check if your payload is valid, like empty title, invalid sound etc

Was this page helpful?
0 / 5 - 0 ratings