Hi there, I've setup Push Notifications for an Android app, and it works great in all the scenarios except when the app is backgrounded but recently active, and a notification is tapped. The onPushNotificationReceived listener isn't being fired at all for some reason.
I see this line in adb logcat when a notification comes in:
09-01 02:55:55.913 22441 22441 I AppCenterPush: Push notification received
But that only appears when the app is currently open. If it is backgrounded then that line does not appear.
Also, a possibly related error I always see with logcat as soon as a notification comes in is:
09-01 02:53:14.137 22441 22491 W FirebaseMessaging: Error while parsing timestamp in GCM event
09-01 02:53:14.137 22441 22491 W FirebaseMessaging: java.lang.NumberFormatException: s == null
09-01 02:53:14.137 22441 22491 W FirebaseMessaging: at java.lang.Integer.parseInt(Integer.java:570)
09-01 02:53:14.137 22441 22491 W FirebaseMessaging: at java.lang.Integer.parseInt(Integer.java:643)
09-01 02:53:14.137 22441 22491 W FirebaseMessaging: at com.google.firebase.messaging.zzb.zzb(Unknown Source:81)
09-01 02:53:14.137 22441 22491 W FirebaseMessaging: at com.google.firebase.messaging.zzb.zzc(Unknown Source:2)
09-01 02:53:14.137 22441 22491 W FirebaseMessaging: at com.google.firebase.messaging.FirebaseMessagingService.zzd(Unknown Source:353)
09-01 02:53:14.137 22441 22491 W FirebaseMessaging: at com.google.firebase.iid.zzg.run(Unknown Source:26)
09-01 02:53:14.137 22441 22491 W FirebaseMessaging: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
09-01 02:53:14.137 22441 22491 W FirebaseMessaging: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
09-01 02:53:14.137 22441 22491 W FirebaseMessaging: at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:7)
09-01 02:53:14.137 22441 22491 W FirebaseMessaging: at java.lang.Thread.run(Thread.java:764)
09-01 02:53:14.158 22441 22491 W FirebaseMessaging: Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
09-01 02:53:14.223 765 774 I zygote64: Background concurrent copying GC freed 66632(3MB) AllocSpace objects, 12(624KB) LOS objects, 42% free, 17MB/29MB, paused 208us total 124.776ms
09-01 02:53:14.324 1042 1042 I zygote64: Deoptimizing void com.android.systemui.statusbar.notification.NotificationViewWrapper.onReinflated() due to JIT same target
I can try to make a repro repo, but just wanted to see if there were any suggestions of where to start looking first.
5.
react-native info command output:
React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Memory: 764.03 MB / 16.00 GB
Shell: 2.7.1 - /usr/local/bin/fish
Binaries:
Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
Yarn: 1.9.4 - ~/.nvm/versions/node/v8.11.3/bin/yarn
npm: 6.1.0 - ~/.nvm/versions/node/v8.11.3/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
Android SDK:
Build Tools: 23.0.1, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.2, 27.0.3
API Levels: 23, 24, 25, 26, 27
IDEs:
Android Studio: 3.0 AI-171.4443003
Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
npmPackages:
@storybook/react-native: ^3.4.10 => 3.4.10
@types/apollo-upload-client: ^8.1.0 => 8.1.0
@types/babel-core: ^6.25.5 => 6.25.5
@types/chalk: ^2.2.0 => 2.2.0
@types/date-fns: ^2.6.0 => 2.6.0
@types/eslint: ^4.16.3 => 4.16.3
@types/graphql: ^0.13.4 => 0.13.4
@types/inquirer: ^0.0.43 => 0.0.43
@types/jest: ^23.3.1 => 23.3.1
@types/lodash: ^4.14.116 => 4.14.116
@types/moment: ^2.13.0 => 2.13.0
@types/prettier: ^1.13.2 => 1.13.2
@types/prop-types: ^15.5.5 => 15.5.5
@types/qs: ^6.5.1 => 6.5.1
@types/react: ^16.4.13 => 16.4.13
@types/react-dom: ^16.0.7 => 16.0.7
@types/react-native: ^0.56.15 => 0.56.15
@types/react-native-datepicker: ^1.6.5 => 1.6.5
@types/react-native-fbsdk: ^0.6.2 => 0.6.2
@types/react-native-htmlview: ^0.12.2 => 0.12.2
@types/react-native-keyboard-spacer: ^0.4.1 => 0.4.1
@types/react-native-loading-spinner-overlay: ^0.5.1 => 0.5.1
@types/react-native-modal: ^4.1.1 => 4.1.1
@types/react-native-permissions: ^1.1.1 => 1.1.1
@types/react-native-safari-view: ^2.0.4 => 2.0.4
@types/react-native-sortable-list: ^0.0.7 => 0.0.7
@types/react-native-vector-icons: ^4.6.3 => 4.6.3
@types/react-navigation: ^2.0.19 => 2.0.19
@types/react-test-renderer: ^16.0.2 => 16.0.2
@types/react-timeout: ^1.1.1 => 1.1.1
@types/styled-components: ^3.0.0 => 3.0.0
apisauce: ^0.16.0 => 0.16.0
apollo-cache-inmemory: ^1.2.9 => 1.2.9
apollo-cache-persist: ^0.1.1 => 0.1.1
apollo-client: ^2.4.1 => 2.4.1
apollo-link: ^1.2.2 => 1.2.2
apollo-link-batch-http: ^1.2.2 => 1.2.2
apollo-link-context: ^1.0.8 => 1.0.8
apollo-link-error: ^1.1.0 => 1.1.0
apollo-link-token-refresh: ^0.2.3 => 0.2.3
apollo-upload-client: ^8.1.0 => 8.1.0
appcenter: 1.7.1 => 1.7.1
appcenter-analytics: 1.7.1 => 1.7.1
appcenter-cli: ^1.1.2 => 1.1.2
appcenter-crashes: 1.7.1 => 1.7.1
appcenter-push: 1.7.1 => 1.7.1
babel-bridge: ^1.12.11 => 1.12.11
babel-core: 7.0.0-bridge.0 => 7.0.0-bridge.0
babel-eslint: 9.0.0-beta.3 => 9.0.0-beta.3
babel-jest: 23.4.2 => 23.4.2
babel-plugin-module-resolver: ^3.1.1 => 3.1.1
babel-plugin-transform-remove-console: ^6.9.4 => 6.9.4
babel-preset-react-native: 5.0.2 => 5.0.2
babel-runtime: ^6.26.0 => 6.26.0
bugsnag-build-reporter: ^1.0.0 => 1.0.0
bugsnag-react-native: 2.10.2 => 2.10.2
bugsnag-sourcemaps: ^1.0.4 => 1.0.4
chalk: ^2.4.1 => 2.4.1
date-fns: ^1.29.0 => 1.29.0
eslint: ^4.19.1 => 4.19.1
eslint-config-airbnb: ^17.1.0 => 17.1.0
eslint-config-prettier: ^3.0.1 => 3.0.1
eslint-import-resolver-babel-module: ^5.0.0-beta.1 => 5.0.0-beta.1
eslint-plugin-babel: ^5.1.0 => 5.1.0
eslint-plugin-graphql: ^2.1.1 => 2.1.1
eslint-plugin-import: 2.14.0 => 2.14.0
eslint-plugin-jest: ^21.22.0 => 21.22.0
eslint-plugin-jsx-a11y: ^6.1.1 => 6.1.1
eslint-plugin-react: ^7.11.1 => 7.11.1
eslint-plugin-react-native: ^3.2.1 => 3.2.1
fs: ^0.0.1-security => 0.0.1-security
get-graphql-schema: ^2.1.1 => 2.1.1
graphql: ^0.13.2 => 0.13.2
graphql-tag: ^2.9.2 => 2.9.2
husky: ^0.14.3 => 0.14.3
inquirer: ^6.2.0 => 6.2.0
jest: 23.5.0 => 23.5.0
jsc-android: ^224109.1.0 => 224109.1.0
lint-staged: ^7.2.2 => 7.2.2
lodash: ^4.17.10 => 4.17.10
mobx: ^5.1.0 => 5.1.0
mobx-persist: ^0.4.1 => 0.4.1
mobx-react: ^5.2.5 => 5.2.5
patch-package: ^5.1.1 => 5.1.1
postinstall-postinstall: ^1.0.0 => 1.0.0
prettier: ^1.14.2 => 1.14.2
prop-types: ^15.6.2 => 15.6.2
qs: ^6.5.2 => 6.5.2
react: 16.4.1 => 16.4.1
react-apollo: ^2.1.11 => 2.1.11
react-dom: 16.4.1 => 16.4.1
react-native: 0.56.0 => 0.56.0
react-native-add-calendar-event: ^2.1.0 => 2.1.0
react-native-analytics-segment-io: ^3.1.3 => 3.1.3
react-native-android-settings-library: ^1.0.5 => 1.0.5
react-native-button: ^2.3.0 => 2.3.0
react-native-code-push: ^5.4.2 => 5.4.2
react-native-datepicker: ^1.7.2 => 1.7.2
react-native-device-info: ^0.22.5 => 0.22.5
react-native-display: ^1.0.8 => 1.0.8
react-native-fast-image: ^5.0.3 => 5.0.3
react-native-fbsdk: ^0.7.0 => 0.7.0
react-native-fit-image: ^1.5.4 => 1.5.4
react-native-geolocation-service: ^1.1.0 => 1.1.0
react-native-htmlview: ^0.13.0 => 0.13.0
react-native-image-crop-picker: ^0.21.1 => 0.21.1
react-native-keyboard-aware-scroll-view: ^0.7.2 => 0.7.2
react-native-keyboard-spacer: ^0.4.1 => 0.4.1
react-native-loading-spinner-overlay: ^0.5.2 => 0.5.2
react-native-looped-carousel: ^0.1.13 => 0.1.13
react-native-map-link: ^2.1.0 => 2.1.0
react-native-maps: ^0.21.0 => 0.21.0
react-native-modal: ^6.5.0 => 6.5.0
react-native-offline: ^3.11.1 => 3.11.1
react-native-parsed-text: ^0.0.20 => 0.0.20
react-native-permissions: ^1.1.1 => 1.1.1
react-native-phone-call: ^1.0.8 => 1.0.8
react-native-progress: ^3.5.0 => 3.5.0
react-native-responsive-image: ^2.3.1 => 2.3.1
react-native-row: ^1.1.1 => 1.1.1
react-native-safari-view: ^2.1.0 => 2.1.0
react-native-schemes-manager: ^1.0.5 => 1.0.5
react-native-sortable-list: ^0.0.22 => 0.0.22
react-native-splash-screen: 3.1.1 => 3.1.1
react-native-storybook-loader: ^1.8.0 => 1.8.0
react-native-svg: ^6.5.2 => 6.5.2
react-native-ui-lib: ^3.3.226 => 3.3.226
react-native-vector-icons: ^5.0.0 => 5.0.0
react-native-version: ^2.6.5 => 2.6.5
react-native-wkwebview-reborn: ^1.21.0 => 1.21.0
react-navigation: ^2.12.1 => 2.12.1
react-test-renderer: 16.4.1 => 16.4.1
react-timeout: ^1.1.1 => 1.1.1
serializr: ^1.3.0 => 1.3.0
solidarity: ^2.1.0 => 2.1.0
solidarity-react-native: ^2.0.2 => 2.0.2
Was able to fix that timestamp parsing error by upgrading to com.google.firebase:firebase-messaging:17.3.0 as mentioned here.
I cannot reproduce the issue with 17.1.0 but glad that work around worked for you.
We cannot automatically pull 17.3.0 just yet because of the issue explained in https://github.com/Microsoft/AppCenter-SDK-React-Native/issues/365#issuecomment-414431329 but we keep monitoring when Firebase will update the core.
Thanks for using AppCenter.
Hey @guperrot thanks for replying, I meant with my follow up comment that upgrading to 17.3.0 fixes just the java.lang.NumberFormatException, but the push notification listener still isn't firing when the app is backgrounded and a user taps on a notification so all that happens is the app opens with no way for us to direct them to a specific screen. The listener does fire correctly if the app is open, or completely closed.
I cannot reproduce the issue with our test apps, clicking on the notification on recently closed correctly triggers the listener.
What does the launcher activity looks like in your AndroidManifest.xml? Did you customize MainApplication.java or other Java code?
How and when do you setup the Javascript listener and what does it do?
Can you increase log level to verbose in MainApplication.java before SoLoader.init by calling AppCenter.setLogLevel(Log.Verbose) and in logcat logs look for AppCenterPush logs.
When the event is fired on clicking notifications, this is what is expected on the logs:
09-07 12:34:03.169 21372-21372/? I/AppCenterPush: Clicked push message from background id=0:1536348836973769%a85f0df1a85f0df1
09-07 12:34:03.169 21372-21372/? D/AppCenterPush: Push intent extras=Bundle[{google.delivered_priority=high, google.sent_time=1536348836945, google.ttl=2419200, google.original_priority=high, from=177539951155, google.message_id=0:1536348836973769%a85f0df1a85f0df1, collapse_key=com.demoapp}]
09-07 12:34:03.169 21372-21372/? I/AppCenterPush: Push notification received
Is there a scenario where you see those logs but your code is either not executed or not redirecting to your screen?
Hey @guperrot thanks for the suggestions. My Android device isn't working at the moment so just waiting on a new one to come in then I'll follow up on this, sorry about the wait and thanks again for your help!
This is followed up on Intercom support channel. I am closing this for now, please feel free to contact us on GitHub or Intercom any time you have more questions.
I have the same issue.
onPushNotificationReceived only runs in these scenarios:
1) app is active and open
2) app is closed completely AND is opened by tapping on the push notification
onPushNotificationReceived does not run in these scenarios:
1) app is active but in background
2) app is opened by tapping on the app icon (as opposed to taping on the push notification)
my appcenter-push version is 1.10.0
Hi @mojtaba-hajishah !
I've just rechecked and I receive onPushNotificationReceived event when the app is active but in the background. I don't think that this event should be triggered when you start the app from the launcher, when tapping on the app icon. That's by design of android os.
As for the first scenario could you please provide the code how are you setting Push listener? Also could you please provide log from javascript console and verbose log from android logcat. To enable verbose logging on Android please make following modifications to your MainApplication.java:
import com.microsoft.appcenter.AppCenter; to the imports section at the top of the file.onCreate callback to look like this:@Override
public void onCreate() {
super.onCreate();
AppCenter.setLogLevel(Log.VERBOSE);
SoLoader.init(this, /* native exopackage */ false);
}
@bmourat
We are experiencing the same behavior (notifications are not received when app was put into background recently).
Our environment:
I'm asking about "don't keep activities" because it looks like this happens only when an activity is still alive and should be handled in onNewIntent.
@DesmanLead if you use singleTask you need to call a method explicitly on onNewIntent as documented in https://docs.microsoft.com/en-us/appcenter/sdk/push/react-native-android#intercept-push-notifications
import com.microsoft.appcenter.push.Push;
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Push.checkLaunchedFromNotification(this, intent);
}
In MainActivity.java.
This is not a callback that can be captured automatically by the SDK contrary to onResume.
@guperrot good point, thanks! We missed that part of documentation. Now it works.
To be fair that part of the documentation was missing on React Native until March 18th. It was there for
other platforms.
Glad the solution worked for you and thanks for using AppCenter.