From a97635e0e20eacf6ef31b59d08da5e6300754081 Mon Sep 17 00:00:00 2001 From: Boris Tacyniak Date: Thu, 4 Mar 2021 20:01:56 +0100 Subject: [PATCH] Fixes #1878 --- CHANGELOG.md | 18 ++++++++++++------ .../modules/RNPushNotificationHelper.java | 7 ++++++- example/App.js | 7 +++++++ example/NotifService.js | 4 ++++ package.json | 2 +- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 002c29e68..844bcaa53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,36 +12,42 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html ### Fixed +## [7.2.2] 2021-03-04 + +### Fixed + +- (Android) Fix: Could not invoke RNPushNotification.getDeliveredNotifications. [#1878](https://github.com/zo0r/react-native-push-notification/issues/1878) + ## [7.2.1] 2021-02-11 ### Fixed -- (iOS) Fix `playSound` options on local notifications. [1858](https://github.com/zo0r/react-native-push-notification/issues/1858#issuecomment-775714298) +- (iOS) Fix `playSound` options on local notifications. [#1858](https://github.com/zo0r/react-native-push-notification/issues/1858#issuecomment-775714298) ## [7.2.0] 2021-01-24 ### Features -- (Android) Handle localization for notification title and body [1837](https://github.com/zo0r/react-native-push-notification/pull/1837) +- (Android) Handle localization for notification title and body [#1837](https://github.com/zo0r/react-native-push-notification/pull/1837) ## [7.1.1] 2021-01-20 ### Fixed -- (Android) unsubscribeFromTopic function fix [1831](https://github.com/zo0r/react-native-push-notification/pull/1831) +- (Android) unsubscribeFromTopic function fix [#1831](https://github.com/zo0r/react-native-push-notification/pull/1831) ## [7.1.0] 2021-01-16 # Features -- (Android) Add hooks to intent handling and bundle parsing [1819](https://github.com/zo0r/react-native-push-notification/pull/1819) +- (Android) Add hooks to intent handling and bundle parsing [#1819](https://github.com/zo0r/react-native-push-notification/pull/1819) ## [7.0.0] 2020-12-23 ### Breaking changes -- (iOS) Replace deprecated local notification methods on iOS [1751](https://github.com/zo0r/react-native-push-notification/pull/1751) -- (Android) Rename the Android package from `RNPushNotification` to `ReactNativePushNotification` resolve [893](https://github.com/zo0r/react-native-push-notification/issues/893) +- (iOS) Replace deprecated local notification methods on iOS [#1751](https://github.com/zo0r/react-native-push-notification/pull/1751) +- (Android) Rename the Android package from `RNPushNotification` to `ReactNativePushNotification` resolve [#893](https://github.com/zo0r/react-native-push-notification/issues/893) - (Android) Allow `userInfo` to be stored in scheduled notification as in iOS (mapped as `data` on press or list scheduled notifications). ### Features diff --git a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java index a9199bf6a..ad3527bcb 100644 --- a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java +++ b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java @@ -723,10 +723,15 @@ public void clearDeliveredNotifications(ReadableArray identifiers) { @RequiresApi(api = Build.VERSION_CODES.M) public WritableArray getDeliveredNotifications() { + WritableArray result = Arguments.createArray(); + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + return result; + } + NotificationManager notificationManager = notificationManager(); StatusBarNotification delivered[] = notificationManager.getActiveNotifications(); Log.i(LOG_TAG, "Found " + delivered.length + " delivered notifications"); - WritableArray result = Arguments.createArray(); /* * stay consistent to the return structure in * https://facebook.github.io/react-native/docs/pushnotificationios.html#getdeliverednotifications diff --git a/example/App.js b/example/App.js index 5d2f03973..eb08ef637 100644 --- a/example/App.js +++ b/example/App.js @@ -112,6 +112,13 @@ export default class App extends Component { }}> Console.Log Scheduled Local Notifications + { + this.notif.getDeliveredNotifications(notifs => console.log(notifs)); + }}> + Console.Log Delivered Notifications + { diff --git a/example/NotifService.js b/example/NotifService.js index 792668268..c57ccfc9c 100644 --- a/example/NotifService.js +++ b/example/NotifService.js @@ -170,4 +170,8 @@ export default class NotifService { getScheduledLocalNotifications(callback) { PushNotification.getScheduledLocalNotifications(callback); } + + getDeliveredNotifications(callback) { + PushNotification.getDeliveredNotifications(callback); + } } diff --git a/package.json b/package.json index cf67d53ef..0f1108548 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-push-notification", - "version": "7.2.1", + "version": "7.2.2", "description": "React Native Local and Remote Notifications", "main": "index.js", "scripts": {