Closed saravananangu closed 5 years ago
When app is closed, notification will happen, but the callback (JavaScript) will not be triggered.
When push sends, it will trigger the app's main Application class. But since React Native is still inactive, all JavaScript codes will not run, including the Flurry Push callback.
This behavior is for app is closed, when app is in background, the callback will be triggered.
When app is closed, notification will happen, but the callback (JavaScript) will not be triggered.
When push sends, it will trigger the app's main Application class. But since React Native is still inactive, all JavaScript codes will not run, including the Flurry Push callback.
This behavior is for app is closed, when app is in background, the callback will be triggered.
Yes We need payload data while open tray notification in app
From issue #12,
The Problem is while i m clicking the tray, i didn't not get payload data console(debug mode) or alert. At the time app is closed
Flurry.addMessagingListener((message) => { });
not working
As I described before, React Native JavaScript is inactive, hence there is no way (from JavaScript) to get the callback when app is closed. This will not be fixed due to the React Native platform limitation.
However, there is one way to add your native Push listener in the following Android Java code.
$YourProjectRoot/node_modules/react-native-flurry-sdk/android/src/main/java/com/flurry/android/reactnative/FlurryModule.java
.
// first enable the listener flag
enableMessagingListener(true);
// add your codes in the provided listener
static class RNFlurryMessagingListener implements FlurryMessagingListener {
...
@Override
public boolean onNotificationReceived(FlurryMessage flurryMessage) {
if (sEnableMessagingListener && (sReactApplicationContext != null)) {
// Your codes here.
return sendEvent(EventType.NotificationReceived, flurryMessage, true);
}
return false;
}
Note: even you can get payload data from the native listener, you can't use them immediately in your JavaScript codes. Because React Native engine is still not alive at that time. This is the life cycle behavior of React Native platform.
As I described before, React Native JavaScript is inactive, hence there is no way (from JavaScript) to get the callback when app is closed. This will not be fixed due to the React Native platform limitation.
However, there is one way to add your native Push listener in the following Android Java code.
$YourProjectRoot/node_modules/react-native-flurry-sdk/android/src/main/java/com/flurry/android/reactnative/FlurryModule.java
.// first enable the listener flag enableMessagingListener(true); // add your codes in the provided listener static class RNFlurryMessagingListener implements FlurryMessagingListener { ... @Override public boolean onNotificationReceived(FlurryMessage flurryMessage) { if (sEnableMessagingListener && (sReactApplicationContext != null)) { // Your codes here. return sendEvent(EventType.NotificationReceived, flurryMessage, true); } return false; }
where is enableMessagingListener(true), where i have to give? . we have sEnableMessagingListener in flurryModule.java file . sReactApplicationContext is return null
where is enableMessagingListener(true), where i have to give? . we have sEnableMessagingListener in flurryModule.java file
If you set your JavaScript listener, then this will be called automatically. Otherwise, just change the default to true for sEnableMessagingListener.
sReactApplicationContext is return null
Looks like you did not use FlurryModule.Builder() as described in the README! If you want to use Push for Android, please follow README.
// In your MainApplication.java
new FlurryModule.Builder()
.withCrashReporting(true)
.withLogEnabled(true)
.withLogLevel(Log.VERBOSE)
.withMessaging(true, options_or_listener) // optional user's native `FlurryMarketingOptions` or `FlurryMessagingListener`.
.build(this, FLURRY_ANDROID_API_KEY);
We needed this functionality for our App as well. I created a java class implementing the FlurryMessagingListener
, mostly copied from their source code. Instead of immediately calling sendEvent
, you can create a new Thread
that continually null-checks the getRNAContext()
until the React Native env is available.
Not sure why something like this cannot be implemented by default, it's certainly not an obscure use case.
@saravananangu @cboar Our plugin does support adding customized Push listener natively for Android, see
public Builder withMessaging(boolean enableMessaging, FlurryMessagingListener messagingListener)
However, based on the SDK design, it's pretty risky to use sleep-wake-loop background thread to wait for not-yet-available React Native platform to become alive.
Yes, we will continue looking for a safe way to add this kind of feature. @cboar Thanks a lot for your valuable feedback!
i have done this way, it is working fine . we can get payload data at the time of click tray when app is closed in Android push notification
`public boolean onNotificationClicked(final FlurryMessage flurryMessage) {
sEnableMessagingListener = true;
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
if (sEnableMessagingListener && (sReactApplicationContext != null)) {
Log.d("Clicked",flurryMessage);
sendEvent(EventType.NotificationClicked, flurryMessage, true);
}
}
},
900);
return false;
}`
@saravananangu Thanks a lot for the helpful info! Yes, this is a known behavior when React Native platform is not yet available. As I described before, we will continue looking for a safe way to add this kind of feature. Thanks!
@saravananangu FYI, your approach delays the Click event so React Native is alive at that time. However, the Notify event will not work under this delay (and Cancel). We may need a dedicated thread running under loop waiting for React Native platform become alive to cover them all.
@saravananangu FYI, your approach delays the Click event so React Native is alive at that time. However, the Notify event will not work under this delay (and Cancel). We may need a dedicated thread running under loop waiting for React Native platform become alive to cover them all.
@poting-oath Notify event is working . we have sReactApplicationContext value after delay , main problem is we didn't get tray notification in react native the only reason is the react native emitter is calling after tray click. now my code is working now when click on tray. we hope you will fix this in flurry sdk module .
@saravananangu @cboar We just released 5.0.0 that should handle this closed app issue. After clicked on the Notification, the JavaScript callback will return the payload after app starts.
BTW, we do not use extra thread, or sleep loop, to do this. Instead, we use React Native lifecycle to do this task which is reliable and low risk for SDK. Thanks!
Fixed in 5.0.0.
The Problem is while i m clicking the tray, i didn't not get payload data console(debug mode) or alert. At the time app is closed