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

[expo-notifications][Android] Get notification responses when app in background or not running #28883

Conversation

douglowder
Copy link
Contributor

Why

After the Android notifications change to FCMv1, the app is not able to get notification response listeners to fire when the app is in background or not running, and opened in response to a notification.

How

This change leverages the Expo module Android lifecycle listeners to get the notification data from the lifecycle methods, and pass them to the notification emitter that emits notifications and responses to JS.

This change also includes support for the useLastNotificationResponse() hook. This is especially important if the app is not running and is opened in response to a notification, since response listeners may not become active early enough in initial render.

Fixes #14078 .

Test Plan

  • CI should pass
  • Testing with release builds of an Android app on real devices

Checklist

@douglowder douglowder requested a review from tsapeta as a code owner May 15, 2024 01:22
Copy link

linear bot commented May 15, 2024

@expo-bot
Copy link
Collaborator

expo-bot commented May 15, 2024

The Pull Request introduced fingerprint changes against the base commit: 4a28d5b

Fingerprint diff
[
  {
    "type": "dir",
    "filePath": "../../packages/expo-notifications/android",
    "reasons": [
      "expoAutolinkingAndroid"
    ],
    "hash": "aa2d97bfb30fc9086276e1acb2a3672edc201bd5"
  }
]

Generated by PR labeler 🤖

@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels May 15, 2024
@douglowder douglowder merged commit 55e4ad4 into main May 15, 2024
20 checks passed
@douglowder douglowder deleted the doug/eng-12137-android-notificationresponsereceivedlistener-not-called-when branch May 15, 2024 10:57
@brentvatne brentvatne added the published Changes from the PR have been published to npm label May 15, 2024
@douglowder
Copy link
Contributor Author

Fix for #28883 has been published. Pick up latest expo package (51.0.7) and do npx expo install --fix to pick up expo-notifications 0.28.2. You will also get a new version of expo-dev-client that fixes an unnecessary reload issue on Android (see #28893).

delete mappedResponse.notification.request.content.dataString;
}
} catch (e: any) {
console.log(`Error in response: ${e}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these console.log ok?

douglowder added a commit that referenced this pull request Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: fingerprint changed bot: passed checks ExpoBot has nothing to complain about published Changes from the PR have been published to npm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NotificationResponseReceivedListener not called when app is killed
7 participants