question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Notification on android device not showing in any state(background/foreground/killed), although onNotification is called

See original GitHub issue

Bug

Environment info

react-native info output: react-native:0.62.2 firebase-messaging: 20.2.1 and SNS

Library version: 3.1.9> &&<=4.0.0

Steps To Reproduce

  1. Integrate Push Notification in your app
  2. Trigger a Push notification from FCM console, it worked
  3. Trigger a Push notification from SNS console with default payload (in GCM format)
  4. onNotification will be called, notification will be received in callback but notification won’t be shown on your device

Reproducible sample code

export default class PushNotificationController extends Component { constructor(props) { super(props); PushNotification.configure({ // (optional) Called when Token is generated (iOS and Android) onRegister: function(token) { storeObjInPersistentStore(‘notificationToken’, token).then(); },

  // (required) Called when a remote or local notification is opened or received
  onNotification: notification => {
    if (Platform.OS === 'ios' && notification.foreground) {
      showNotificationAlert(
        notification.alert,
        notification,
        handleNotificationTap,
      );
    } else if (!notification.foreground) {
      handleNotificationTap(notification);
    }
  },

  // ANDROID ONLY: GCM or FCM Sender ID (product_number) (optional - not required for local notifications, but is need to receive remote push notifications)
  senderID:MY_FCM_SENDER_ID,

  // IOS ONLY (optional): default: all - Permissions to register.
  permissions: {
    alert: true,
    badge: true,
    sound: true,
  },

  // Should the initial notification be popped automatically
  // default: true
  popInitialNotification: true,

  /**
   * (optional) default: true
   * - Specified if permissions (ios) and token (android and ios) will requested or not,
   * - if not, you must call PushNotificationsHandler.requestPermissions() later
   */
  requestPermissions: true,
});

}

render() { return null; } }

I remember I tried the same using 3.5.2 version on 7th July and it was working using same codebase. But stop working after that. I scratched my head for 4-5 days and at last what I got is that the issue is with version, it started working fine in version 3.1.9 without any further change. I also checked with some other versions but none of them worked in my case.

But I’m not convinced with the solution yet that I got. I request the community to please look at this issue and provide a clear picture of that. Note: I have already tried it with the latest version 4.0.0 but this also didn’t work for me.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:22

github_iconTop GitHub Comments

1reaction
vishal1Singhcommented, Dec 16, 2021

Use this payload as a custom payload in AWS SSN publishing : { “GCM”:“{ “notification”: { “body”: “Sample message for Android endpoints”, “title”:“TitleTest” } }” }

1reaction
kyytiPettericommented, Jul 21, 2020

@Dallas62 Yeah actually this seems to be an issue of Firebase messaging and this lib. Messageid’s from firebase come in completely different format than PushNotification lib gets

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Notifications Not Showing Up? 10 Fixes You Can Try
Not seeing notifications show up on your Android phone? Try these fixes to get Android notifications working again.
Read more >
onNotification() is not fired when app is killed - Stack Overflow
I am not positive but when I remember correctly killing (alias force closing) an app disables the onNotification functionality in Android ...
Read more >
react-native-push-notification - npm
React Native Local and Remote Notifications for iOS and Android ... If not using a built in Android color ( @android:color/{name} ) for...
Read more >
Remote push notification doesn't wake up app
But, whenever the app transitions to the suspended state incoming push notifications do not move it from suspend and into background state, for...
Read more >
Turn App Notifications On / Off - Android - Verizon
1. From a Home screen, do one of the following: Swipe screen then navigate: Settings > Apps & notifications > App info.Navigate: Settings...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found