Skip to content
This repository was archived by the owner on Feb 7, 2019. It is now read-only.
This repository was archived by the owner on Feb 7, 2019. It is now read-only.

Android: Not getting push notification on background #178

Open

Description

@mayureshjadhav

I am using v 0.3.0. I am getting a notification when the app is running but not working while the app is not running.

Activity

  1. lini commented on Jan 8, 2018

    @lini
    Contributor

    Can you share some more details about this issue:

    • are you able to reproduce it using the demo app?
    • what version of Android (device or emulator) are you testing with?
    • what is the content of the notification you are trying to send?
  2. mayureshjadhav commented on Jan 8, 2018

    @mayureshjadhav
    Author

    @lini I am sending following content

    {"to":"[add your token]","data":{"title":"Test Title","body":"Test Description"},"priority":"high"}

    and on notification receive, I am using nativescript-local-notifications plugin to show the notification

     notificationCallbackAndroid: (stringifiedData: string, fcmNotification: any) => {
                    console.log("String Data : " + stringifiedData);
                    console.log("FCM Notification : " + JSON.stringify(fcmNotification)); 
                    let notification = JSON.parse(stringifiedData);
                    LocalNotifications.schedule([{
                                        id: 1,
                                        title: notification.title,
                                        body: notification.body,
                                        ticker: 'The ticker',
                                        badge: 1,
                                        at: new Date(new Date().getTime() + (10 * 1000)) // 10 seconds from now
                                    }]).then(
                                        () => {
                                            console.log("Notification scheduled");
                                        },
                                        (error) => {
                                            console.log("scheduling error: " + error);
                                        }
                                        );
    }
    

    When the app is running I am receiving the notification but when the app is not working I am not getting any notification.

    I am using Moto G device with 5.1 Android version to test this functionality.

  3. tomylee001001 commented on Jan 9, 2018

    @tomylee001001

    as far as i know if you dont send notification part in your json it wont shown when app in background.
    Because default behavior for plugin when app in background is need notification part in your json.i dont know if you change this. but if you change your json like this;
    {"to":"[add your token]",
    "data":{"title":"Test Title","body":"Test Description"},
    "notification": {
    "title": "Test Title",
    "text": "Test Description"
    },
    "priority":"high"}

    it should work both foreground and background

  4. PeterStaev commented on Jan 12, 2018

    @PeterStaev

    @tomylee001001 is correct. But I'm sure it was working before with only sending data in both foreground and background (was using v0.1.2). Not sure if this is because the plugin uses some new version of the native libs or because some change in the plugin, but it should be noted somewhere in the readme/breaking changes for the version.

  5. PeterStaev commented on Jan 12, 2018

    @PeterStaev

    After digging the code for another problem, seems issue came with the removal of the NotificationBuilder class which was pulling the title/message from the data
    https://github.com/NativeScript/push-plugin/blob/0.1.2/native-src/android/app/src/main/java/com/telerik/pushplugin/NotificationBuilder.java#L77
    https://github.com/NativeScript/push-plugin/blob/0.1.2/native-src/android/app/src/main/java/com/telerik/pushplugin/NotificationBuilder.java#L83-L88

    With the removal now we have to use the notification structure. Again this should have been in the Breaking Changes for v0.2 👎

  6. mayureshjadhav commented on Jan 15, 2018

    @mayureshjadhav
    Author

    Still not working

  7. mayureshjadhav commented on Jan 19, 2018

    @mayureshjadhav
    Author

    Is there any updates on it?

  8. mayureshjadhav commented on Feb 28, 2018

    @mayureshjadhav
    Author

    @naiveaiguy It's not working. My scenario is, I am sending following data from server
    {"to":"[add your token]","data":{"title":"Test Title","body":"Test Description"},"priority":"high"} but I am not able to receive it. If I send {"to":"[add your token]","notification":{"title":"Test Title","body":"Test Description"},"priority":"high"} It is working but It shows me the notificatio. I don't want to show the notification. I wanted to pass the data silently without showing it to user.

  9. KkevinLi commented on Jun 26, 2018

    @KkevinLi

    @lini I am getting the same behavior as OP. Using data only notifications I get the notificationCallback() when my app is in the foreground or minimized and in the recent used tray. When I swipe the app away, I see that my data-notifications are cached because no callback was found . Is this the intended behavior?

    When using the android sdk from firebase Quickstart demo, my messageReceivedCallback() gets called even when I swipe the app whereas when I use the NativeScript plugin it doesn't get called unless I relaunch the app.

    This was tested on multiple devices (s8 API 26, pixel, Moto API 24, iPhone X and 6s) using the demo app. I have noticed this in https://github.com/EddyVerbruggen/nativescript-plugin-firebase as well. Is it not possible to replicate the behavior in the FCM Quickstart demos?

  10. michael-dots commented on Sep 18, 2018

    @michael-dots

    Just leaving another bump. I'm using an older GCM library for sending (I really don't want to migrate at this point in time). So no notification structure means i only get the message from within the app.

    Also the message on Android is a string (json encoded) while on ios it's a json object.

    Any plans to fix these or should i look into it myself or get another plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions