zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.73k stars 2.05k forks source link

Is there a way to add fullScreenIntent to a notification? #1482

Open whenmoon opened 4 years ago

whenmoon commented 4 years ago

Question

Hi, I'm looking to move away from custom Java modules for notifications to a React Native package. Currently I am using .setFullScreenIntent(action, true); in my notification builder, but I can't find anything similar in this package. Is there a way to do it, hacky or non-hacky?

whenmoon commented 4 years ago

Ok, I've almost got it and it uses the Telecom API (I think) which is great, but the notification will not dismiss on button click:

RNPushNotificationHelper.java line 273: PendingIntent fullScreenIntent = toScheduleNotificationIntent(bundle);

RNPushNotificationHelper.java line 278: .setFullScreenIntent(fullScreenIntent, true);

AndroidManifest.xml add singleTask:

        <activity
            android:name=".MainActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:launchMode="singleTask"

Anyone have any idea how the button presses can be hooked in to?

Using PushNotification.cancelLocalNotifications() doesn't work.

whenmoon commented 4 years ago

Ok I got it working!

I used this method: clearLocalNotification(id) where id must be an integer.

  PushNotification.configure({
    onNotification: (notification) => {

      //Code to print array into console
      console.log(notification);

      //Code to be executed according to the action selected by the user
      if (notification.action === "Answer") {
        console.log('%c notification.action === "ANSWER"', 'color: green;',);
        PushNotification.clearLocalNotification(1);
      }
      else if (notification.action === "Decline") {
        console.log('%c notification.action === "DECLINE"', 'color: green;',);
      }
    },
    popInitialNotification: true,
    requestPermissions: true,
  });

This basically provides the same interface that Whatsapp or HouseParty provide on an incoming call, which is what I've been looking for almost a year. I'm no Java dev so can't make a pr, but is there a plan to 'officially' support anything this?

twelvearrays commented 4 years ago

@whenmoon I am trying to achieve the same functionality like this for my app. Do you have any more details on how you achieved this? Thanks

whenmoon commented 4 years ago

Hi @twelvearrays, you can either follow the steps above or use this - I forked the current dev branch and published on npm: https://www.npmjs.com/package/react-native-push-notification-full-screen-intent

wiserdivisor commented 3 years ago

Hi @twelvearrays, you can either follow the steps above or use this - I forked the current dev branch and published on npm: https://www.npmjs.com/package/react-native-push-notification-full-screen-intent

This is not working for me. I get notifs but not in full screen? Any special settings for that? @whenmoon can you also, if it's not too much trouble, upload a video demonstrating the full screen notifs?

mateyFromTheBlock commented 2 years ago

Checkout this PR I think it might help: https://github.com/zo0r/react-native-push-notification/pull/2112