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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] onNotificationOpened not called when app is on focus #89

Closed
JonathanWi opened this issue Sep 27, 2016 · 8 comments
Closed

[Android] onNotificationOpened not called when app is on focus #89

JonathanWi opened this issue Sep 27, 2016 · 8 comments
Milestone

Comments

@JonathanWi
Copy link

Hi!

As explained in the title, the onNotificationOpened callback is never called if the app is on focus, and I still receive the push notification (on Android). Everything works fine on iOS, but nothing I've done so far seems to work (enableInAppAlertNotification, configure in the index.android.js)...

What should I do?

@gwleclerc
Copy link

Hi @JonathanWi,
I had the same problem, i looked in the source code and it seems that the documentation is wrong.

Enable Notification When App Active
We exposed the enableNotificationsWhenActive API of OneSignal (Android only).

By default this is false and notifications will not be shown when the user is in your app, instead the NotificationOpenedHandler is fired. If set to true notifications will always show in the notification area and NotificationOpenedHandler will not fire until the user taps on the notification.

By default on Android, enableNotificationsWhenActive is set to true.
Try to add OneSignal.enableNotificationsWhenActive(false); on your index.android.js and it should work.

@JonathanWi
Copy link
Author

Thanks @gwleclerc !

Something really weird is happening: This behavior only works when I'm in dev mode?! How is that possible? any idea?

Cheers!

@JonathanWi
Copy link
Author

Hey, here's an update regarding this — still unresolved for me — issue:

What's happening

Even with the enableNotificationwhenActive function, I still get push notifications above the app.
There are two workarounds for this :

  • Going to Dev Settings (by shaking the phone), and activating (or de-activating) JS Dev Mode.
  • Sending the app in the background, and re-opening it.

Of course, these are not a real workarounds. I need to precise that it's the toggling of the mode that makes it work, not a dev mode in particular.

What I've tried

  • I've tried to move the OneSignal.enableNotificationsWhenActive(false); everywhere.
  • Replaced enableNotificationsWhenActive(false); from true to false in RNOneSignal.java.
  • Installing the highly unstable PR 78. This allowed me to have access to the onNotificationReceived event, which was called when the notification was received, again, above the active app.

My theory

As stated before:

  • This behavior is independent from the dev mode selected
  • The notification is received, just not opened even if the app is active (if pressing the push, I get the expected behavior of my in-app notification displaying etc..).
  • The behavior is fixed by toggling the JS Dev Mode.
  • The behavior is fixed by going back from background mode.

Because of all this, my current theory is that after building, OneSignal detects my app as inactive. Sending the app in background mode (or toggling the Js Dev Mode) forces the app's context to be updated, thus dispatching "I'm active" to OneSignal.

Next steps

I'm looking into the RNOneSignal.java and the other android files in this package to see where the app context is recovered in java.
I have a few leads for this, but I'm far from being a Java expert.

I'll keep you updated on my findings on this :)

@avishayil
Copy link
Contributor

@JonathanWi
Hi, we're closing to finish working upgrading this library to the new Android SDK, should resolve then.

@avishayil avishayil added this to the 2.0.0 milestone Nov 3, 2016
@binaryfoundry
Copy link

I also have this problem on Amdroid and can't find any work around for it. The app is not considered active until sending it to the background and then focused again.

@dvolland
Copy link

Same very annoying problem. Would be great to have a fix. Any update on this?

@DibPuelma
Copy link

Same problem here, onNotificationOpened gets called only after I select "Reload" after shaking the phone.

@avishayil
Copy link
Contributor

Solved with version 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants