Repository: zo0r/react-native-push-notification

Issue #2152: Android notification action reply input not returning reply_text
Created: 2021-09-21T19:00:31Z
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

Send a notification

PushNotification.localNotification({ title, message, userInfo, actions: ["ReplyInput"], reply_palceholderText: "placeholder", reply_button_text: "Reply" })


Notification received on device
Press the reply button and submit a message
Notification handler triggers on device and returns notification without a "reply_text" field, but has everything else

Describe what you expected to happen:

Expected to get reply_text in the notification object with the message I typed in (works in iOS)

Duplicate issue #2129: Android 12: Notifications will no work/crash with SDK 31
Created: 2021-08-30T17:38:20Z
Bug

Environment info

react-native info output:
 System:
    OS: macOS 11.3
    CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
    Memory: 48.70 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.22.1 - /usr/local/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.12 - /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: 28, 29, 30, 31
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 31.0.0
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.7199119
    Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_121 - /usr/bin/javac
    Python: 2.7.15 - /Library/Frameworks/Python.framework/Versions/2.7/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.14.0 => 16.14.0 
    react-native: 0.62.2 => 0.62.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
Library version: 8.0.1
Steps To Reproduce

Running: PushNotification.localNotification({...}) will crash in Android 12.
Due to Android 12 changes, trying to display a local or remote notification will fail with the given error on Android 12 (when compiling with SDK 31):
2021-08-30 14:23:16.910 29950-30022/com.zinspector3.dev E/RNPushNotification: failed to send push notification
    java.lang.IllegalArgumentException: com.zinspector3.dev: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
    Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.

Reference: https://developer.android.com/about/versions/12/behavior-changes-12#pending-intent-mutability
The fix should be as follows: https://github.com/zo0r/react-native-push-notification/blob/master/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java#L453
- PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationID, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
There are also other parts of the code that may use PendingIntent which I haven't tested as I don't use it, but all of these should be updated (https://github.com/zo0r/react-native-push-notification/blob/master/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java#L531).  Also, PendingIntent.FLAG_IMMUTABLE was added in SDK 23, so a build check also needs to be performed, something like:                Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_UPDATE_CURRENT
@Dallas62
Describe what you expected to happen:

No crash

Reproducible sample code

Please review the change and

Closing comment (2021-09-27T15:44:04Z): Wouldn't that fix the issue only for Android < 12? Meaning that Android 12 will still have the issue reported in #2152
The problem is probably related to the actual flags being used, which flag would solve the problem for all android versions?