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 notification action reply input not returning reply_text #2152

Closed
gshenar opened this issue Sep 21, 2021 · 13 comments
Closed

Android notification action reply input not returning reply_text #2152

gshenar opened this issue Sep 21, 2021 · 13 comments
Labels

Comments

@gshenar
Copy link

gshenar commented Sep 21, 2021

Bug

When pushing a notification on Android with a reply action, I am not getting the reply_text back. The notification pops up on the device with the reply action, I can enter a message and click send, but the notification that the application receives, has no "reply_text" field with the message that was typed in.

On iOS this working fine, I see the reply_text field and can handle it accordingly. Any idea why this could be broken?

Environment info

react-native info output:

System:
    OS: macOS 11.5.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 681.73 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.13 - /usr/local/bin/npm
    Watchman: 2021.06.07.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK:
      API Levels: 29, 30
      Build Tools: 29.0.2, 30.0.3
      System Images: android-29 | Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.2 AI-202.7660.26.42.7351085
    Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_292 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: * => 0.64.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Library version: "react-native-push-notification": "^8.1.0",

Steps To Reproduce

  1. Send a notification
PushNotification.localNotification({ title, message, userInfo, actions: ["ReplyInput"], reply_palceholderText: "placeholder", reply_button_text: "Reply" })
  1. Notification received on device
  2. Press the reply button and submit a message
  3. Notification handler triggers on device and returns notification without a "reply_text" field, but has everything else

Describe what you expected to happen:

  1. Expected to get reply_text in the notification object with the message I typed in (works in iOS)
@TongManhCong
Copy link

reason in file RNPushNotificationAcions can't get text in remoteInput => can't callback to js.

Fix:
In filepath: "node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java"

edit
Intent actionIntent = new Intent(context, RNPushNotificationActions.class);
to
Intent actionIntent = new Intent(context, com.dieam.reactnativepushnotification.modules.RNPushNotificationActions.class);

and

edit
int flags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_UPDATE_CURRENT;
to
int flags = PendingIntent.FLAG_UPDATE_CURRENT;

@redexp
Copy link

redexp commented Sep 27, 2021

@TongManhCong thanks! For me, edit flags was enough

@redexp
Copy link

redexp commented Sep 27, 2021

Downgrade to 8.0.1 also fixes issue

@cristianoccazinsp
Copy link
Contributor

@redexp @TongManhCong what happens if you replace PendingIntent.FLAG_IMMUTABLE with PendingIntent.FLAG_MUTABLE instead? Does that also fix the issue? If so, that should be the actual change so it works with all SDKs.

@ammarahm-ed
Copy link

ammarahm-ed commented Oct 14, 2021

@cristianoccazinsp The intent becomes mutable, meaning the values can be changed added to the intent which is required for the reply input to send data on user action.

@chrisspankroy
Copy link
Contributor

(I'm guessing you didn't mean to ping me😄)

@cristianoccazinsp
Copy link
Contributor

Changing it to mutable should fix it I believe.

@Dallas62
Copy link
Collaborator

Dallas62 commented Nov 5, 2021

Changing it to mutable should fix it I believe.

                    int flags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE : PendingIntent.FLAG_UPDATE_CURRENT;
                                                                                                                                  ^
  symbol:   variable FLAG_MUTABLE
  location: class PendingIntent

Nope 🙃

@Dallas62
Copy link
Collaborator

Dallas62 commented Nov 5, 2021

It's working if we use the API version 31, but not with API 30.
image
The only way to avoid this is to force developer to upgrade to target API 31, and also remove some targetCompatibility JavaVersion.VERSION_1_8

@Dallas62
Copy link
Collaborator

Dallas62 commented Nov 5, 2021

I wondering if someone can test this version:

yarn add zo0r/react-native-push-notification#dev

The CHANGELOG is available here: https://github.com/zo0r/react-native-push-notification/blob/dev/CHANGELOG.md#unreleased

@cristianoccazinsp
Copy link
Contributor

Next RN version will also force SDK 31. So it’s a good idea to get ready for it.

For our app, android 12 was full of UI issues that could only be corrected using SDK 31.

@BradSmith252
Copy link

Awesome post! Thanks for posting such informative stuff. Really I’m so excited to read such depth article on push notifications.

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

8 participants