calcazar / react-native-push-notification-CE

The community edition of the push notification library (by Zo0r) for applications made with React Native
MIT License
52 stars 23 forks source link

[Android] When receiving a remote notifications the app opens #18

Open senne-af opened 6 years ago

senne-af commented 6 years ago

When the app is killed (not in background) and it receives a remote notification, it displays the notification but also opens the app. This is bad practice and very intrusive for the user.

However, when the app is in background, the notification shows, but the app does not open.

bhram commented 5 years ago

check this https://github.com/bhram/RNPowerManagerBridge

senne-af commented 5 years ago

Hey @bhram, I don't see how that solves the problem.

mattpetrie commented 5 years ago

Experiencing this as well. @sennevc were you ever able to find a solution?

Steps to reproduce on Android:

  1. Schedule a notification using PushNotification.localNotificationSchedule.
  2. Kill the app (background and then swipe app away in recent apps list)
  3. When notification appears, app will reopen.
senne-af commented 5 years ago

Hey @mattpetrie,

I did some more research and found out that the issue was caused by a conflict between this library and react-native-navigation.

You can read more on it in these threads:

Unfortunately, I didn't find a solution yet and will probably switch to react-native-notifications as soon as android 8 is supported.

mattpetrie commented 5 years ago

@sennevc Thanks! Your reply set me on the right path to get this fixed. This comment mentions this page in the react-native-navigation docs. It's terribly titled -- it really should be called "Handling App Launching in the Background on Android", because that's what it's really about.

Adding the code from there (with one minor modification) to our index.js fixed the issue with the app launching. Posting the full snippet in hopes it helps you too:


import { AppState } from 'react-native'
import {Navigation, NativeEventsReceiver} from 'react-native-navigation'

if (Plaform.OS === 'android') {
  Navigation.isAppLaunched().then(appLaunched => {
    if (appLaunched) startApp())

    new NativeEventsReceiver().appLaunched(() => {
      if (AppState.currentState === 'uninitialized') startApp() // this ensures the app doesn't relaunch if it's already in the background.
    })
} else {
  startApp()
}
likern commented 5 years ago

@sennevc Thanks! Your reply set me on the right path to get this fixed. This comment mentions this page in the react-native-navigation docs. It's terribly titled -- it really should be called "Handling App Launching in the Background on Android", because that's what it's really about.

Adding the code from there (with one minor modification) to our index.js fixed the issue with the app launching. Posting the full snippet in hopes it helps you too:

import { AppState } from 'react-native'
import {Navigation, NativeEventsReceiver} from 'react-native-navigation'

if (Plaform.OS === 'android') {
  Navigation.isAppLaunched().then(appLaunched => {
    if (appLaunched) startApp())

    new NativeEventsReceiver().appLaunched(() => {
      if (AppState.currentState === 'uninitialized') startApp() // this ensures the app doesn't relaunch if it's already in the background.
    })
} else {
  startApp()
}

@sennevc @mattpetrie Sorry, I don't use react-native-navigation. But I'm experiencing the similar issue. My application (when it is in background) moves to foreground if I tap notification action "Complete". The onNotification callback is called and does nothing, but anyway this doesn't help.

Is this related to your cases? I need to perform some stuff in this onNotification callback, but without bringing application to foreground. Just want to complete task and don't show application in foreground.