Commit Graph

29 Commits

Author SHA1 Message Date
Dariusz Luksza 17f7f39dac Implement handling of Android actions in background
There are some cases when local notification action should be handled in
background eg. snoozing the reminder. In case of it launching app UI is
not necessary and would be confusing for the end user.

Therefore there should be a way to handle local notification action in
background.

For this reason new property 'runInBackground' was added to the
AndroidAction class and TypeScript type.

Also new broadcast receiver and service were implemented to handle
properly background actions.

In order to run particular action in background API consumer need to set its
'runInBackground' property to 'true', eg:

  ...
  .android.addAction(new firebase.notifications.Android.Action("snooze",
  "ic_snooze", "Snooze").setRunInBackground(true))
  ...

Then, there are two cases that API consumer needs to handle.

First when app is in the foreground, standard notification and
notification action code path will be executed. This mean, that:
 * onNotification() listener will be called (which should call
 displayNotification(), in order to show it to the user),
 * onNotificationOpen() listener will be called after the action is
 tapped by the user

Secondly, when application is in background or it is not running new
'RNFirebaseBackgroundNotificationAction' handler will be called. To
properly handle this case API consumer should create a background
asynchronous handler:

  const handleAsyncTask = async (notificationOpen: NotifficationOpen) => {
    if (notificationOpen && notificationOpen.notification) {
      const action = notificationOpen.action;
      const notificationId = notificationOpen.notification.notificationId;
      if (action === "snooze") {
        console.log("Reschedule notification for later time", notificationId);
      } else {
        console.log("unsupported action", action);
      }
      // hide the notification
      firebase.notifications().removeDeliveredNotification(notificationId);
    }
  }

Next hander should be registered to headless handler:

  AppRegistry.registerHeadlessTask('RNFirebaseBackgroundNotificationAction', () => handleAsyncTask);

Finally AndroidManifest.xml file must be modified, to include receiver
and service definition:

  <receiver
      android:name="io.invertase.firebase.notifications.RNFirebaseBackgroundNotificationActionReceiver"
      android:exported="true">
    <intent-filter>
      <action android:name="io.invertase.firebase.notifications.BackgroundAction"/>
    </intent-filter>
  </receiver>
  <service android:name="io.invertase.firebase.notifications.RNFirebaseBackgroundNotificationActionsService"/>

Now when ever 'Snooze' action is pressed it will launch
'handleAsyncTask' function in the background or onNotificationOpen()
when app is in foreground. And reschedule the notification
for the later time.
2018-05-16 08:20:24 +02:00
Dariusz Luksza 57901cd29a Add Android API to delete channel and channel group 2018-05-14 09:24:44 +02:00
TaopaiC 5f7edf668c fix allowedDataTypes in fromNativeAndroidRemoteInput 2018-05-01 23:45:55 +08:00
Chris Bianca 0645d179b3 [notifications] Make title and body optional fields 2018-04-11 18:15:38 +01:00
Chris Bianca f5fa7436a9 [notifications] Add enableLights and enableVibration to AndroidChannel 2018-03-31 15:42:14 +01:00
Chris Bianca 801adabb27 [notifications] Add jsInitialised method to improve getInitialNotification 2018-03-30 10:31:06 +01:00
Chris Bianca d101813b5f [messaging][notifications] Make all methods return a promise where they didn’t previously 2018-03-28 11:02:39 +01:00
Chris Bianca 6ff34f4daa [notifications] Add support for Android BigPictureStyle and BigTextStyle 2018-03-27 16:15:31 +01:00
Chris Bianca 8a9033457d [tests] Fix various test errors 2018-03-23 17:03:53 +00:00
Chris Bianca 7f90e485c8 [links] Refactor links to use builder classes 2018-03-23 13:24:31 +00:00
Chris Bianca 287ad216cf [notifications] Fix flow type 2018-03-09 11:15:27 +00:00
Chris Bianca e537955212 [notifications] Add support for android actions 2018-03-09 11:09:28 +00:00
Chris Bianca 57ffa9bd3e [notifications] Fix some android issues with local notifications 2018-03-07 18:29:53 +00:00
Chris Bianca 7b9269fec5 [notifications] Rename `onNotificationOpened` to `onNotificationOpen` 2018-03-06 18:20:49 +00:00
Chris Bianca b9df258402 [notifications] Android channel and channel group support 2018-03-05 08:28:13 +00:00
Chris Bianca 7acace4ce6 [notifications][ios] Properly define attachment options 2018-03-01 08:39:24 +00:00
Chris Bianca ee3b2932ef [notifications] Rename `onPressed` to `onOpened` 2018-02-24 11:32:14 +00:00
Chris Bianca c5778c3d0d [notifications] JS tidy up 2018-02-23 16:11:59 +00:00
Chris Bianca 2838bbc0cd [notifications] Last part of iOS implementation 2018-02-23 15:34:00 +00:00
Chris Bianca 8e84dd576b [notifications] Specific notificationPressed data type including action 2018-02-22 17:25:15 +00:00
Chris Bianca 303cb4c428 [notifications] Refactor for better support of separate messages 2018-02-22 15:52:24 +00:00
Chris Bianca a244f17853 [fcm] More iOS event separation 2018-02-18 16:02:31 +00:00
Chris Bianca 9255b4be10 [notifications] Minor fixes 2018-02-16 09:46:53 +00:00
Chris Bianca cd0ef4e3b7 [notifications] Continue android implementation 2018-02-15 14:59:21 +00:00
Chris Bianca 99b4b6550b [notifications] WIP Android implementation 2018-02-15 08:11:17 +00:00
Chris Bianca 6b911b207b [notifications] Start iOS implementation of notifications 2018-02-14 09:07:29 +00:00
Chris Bianca fb57dc5482 [notifications] First pass at notifications JS API 2018-02-09 17:00:03 +00:00
Chris Bianca 850f04914f [fcm] Android instanceid and core fcm support; iOS instance and basic fcm support 2018-02-02 08:40:48 +00:00
Chris Bianca d429db7e86 [fcm] First steps towards identifying the new API for messaging / notifications 2018-01-30 11:15:59 +00:00