Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push notification listener is not invoked at all Android #4183

Closed
vinaynb opened this issue May 10, 2019 · 6 comments
Closed

Push notification listener is not invoked at all Android #4183

vinaynb opened this issue May 10, 2019 · 6 comments

Comments

@vinaynb
Copy link

vinaynb commented May 10, 2019

馃悰 Bug Report

Environment

Expo CLI 2.17.1 environment info:
    System:
      OS: Linux 3.13 Ubuntu 14.04.5 LTS, Trusty Tahr
      Shell: 5.0.2 - /usr/bin/zsh
    Binaries:
      Node: 8.3.0 - ~/.nvm/versions/node/v8.3.0/bin/node
      npm: 5.3.0 - ~/.nvm/versions/node/v8.3.0/bin/npm
    npmPackages:
      expo: ^32.0.0 => 32.0.6 
      react: 16.5.0 => 16.5.0 
      react-native: https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz => 0.57.1 
      react-navigation: ^3.0.9 => 3.3.0 
    npmGlobalPackages:
      expo-cli: 2.17.1

standalone android

Steps to Reproduce

  • get native device token using Notifications.getDevicePushTokenAsync
  • build standalone apk using expo build:android
  • install and run on physical device
  • send push notification using aws sns and firebase
  • notification is recieved successfully on device and shows up in system tray
  • click on notification and app opens but the notifications listener never gets called

Expected Behavior

I have copied notifications code from Expo's documentation and implemented in-app. The listener should fire when user opens app by tapping notification.

Actual Behavior

Notification listener is not fired at all even once.

Reproducible Demo

i can provide a repro via snack but that wouldn't be of help in my case as you need to have standalone apk to get device native token as I am not using expo's notifications service.

my listener code is written on root component's componentDidMount and i can confirm that it is being called.

componentDidMount(){
this._notificationSubscription = Notifications.addListener(this._handleNotification);
}
_handleNotification = (notification) => {
        alert('notification');
        //this.setState({ notification: notification });
    };

This issue is very similar to #1997 except that i use aws sns and i am facing this issue on android

@vinaynb vinaynb changed the title Push notification is not invoked at all Android Push notification listener is not invoked at all Android May 10, 2019
@cruzach
Copy link
Contributor

cruzach commented May 10, 2019

Hi @vinaynb ,

Since you're not using FCM for your Android Push Notifications, I'm not sure this is an Expo-related issue. The payload format could be different with AWS SNS.

Please take a look at this forum post for a possible solution.

Closing as I don't believe this is Expo-related, will re-open if necessary.
-Charlie

@cruzach cruzach closed this as completed May 10, 2019
@vinaynb
Copy link
Author

vinaynb commented May 11, 2019

@cruzach i am using FCM for push android notifications just the difference is that it does via AWS SNS and not via Expo Servers. Can you guide me to the required format which i need to take care of when sending notifications.

Closing as I don't believe this is Expo-related, will re-open if necessary.

As i am recieving notifications successfully and the app opens up as well but listener doesn't get called leads me to something wrong happening in expo.

@vinaynb
Copy link
Author

vinaynb commented May 13, 2019

UPDATE - today i checked the same on iOS and it works so issue is specifically hitting android right now.

@cruzach
Copy link
Contributor

cruzach commented May 13, 2019

See these Github issue comments, as that seems to be the issue. Not 100% sure if that exact fix will work, but taking a look at our source code for Notifications will let you see the exact payload to model.

@vinaynb
Copy link
Author

vinaynb commented May 14, 2019

UPDATE
I managed to solve it. Thanks @cruzach for the pointers. For other's who might come to this issue with the same problem using below json in AWS SNS with FCM fixed the issue.

{
"GCM": "{ \"data\": { \"message\": \"Sample message for Android endpoints\", \"title\": \"Hello world...\", \"body\": \"msg body\", \"experienceId\": \"@expousername/app-slug\" } }"
}

experienceId and data properties were the missing piece. Your app slug can obtained from app.json file in your root directory of expo project.

old json which didn't work (for reference)

{
  "GCM": "{ \"notification\": { \"message\": \"Sample message for Android endpoints\", \"title\": \"Hello You...\" } }"
}

Another issue that i solved with new json was that of double notifications being shown in android. The reason behind that was because of the notification key expo was triggering another local notification of its own along with the push notification. Replacing it with data key fixed that.

@cruzach
Copy link
Contributor

cruzach commented May 14, 2019

Awesome! And thanks for sharing the fix for others who might run into the same problem 馃槃

@lock lock bot added the outdated label Nov 10, 2019
@lock lock bot locked and limited conversation to collaborators Nov 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants