1

I have implemented pushy notification in my react-native project following below link: https://pushy.me/docs/additional-platforms/react-native

I am facing problem on Android, I am getting the notification but on clicking on notification from the notification bar, I am not getting any callback or control on react-native method => Pushy.setNotificationListener

According to documentation, we have to get the call in Pushy.setNotificationListener method.

Please let us know how to proceed in this as soon as possible.

Yogendra Girase
  • 631
  • 3
  • 15
  • I think Pushy.setNotificationListener is called when the notification is received not when it opened. I'm currently looking for a way to handle notification opened behavior. for me clicking the notification relaunched the app from the start and destroys the app state. I don't want that behavior, I want my app to persist its state when opened from notification. any ideas ? – Tarik Chakur Oct 10 '18 at 10:12
  • 1
    @TarikChakur you found anything on this? – Ahsan Hussain Mar 17 '19 at 06:47
  • Hi Hussain.To preserve the app state and avoid its restart when opening it from the notification, in your splash screen ( first activity launched in the android app ). Check if that activity is the root one or not. public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ...... if ( !isTaskRoot() ) { finish(); return; } ..... } } – Tarik Chakur Mar 19 '19 at 11:23

1 Answers1

1

You may now call the Pushy.setNotificationClickListener((data) => {}) method from your application to listen for when the user clicks your notifications:

// Listen for push notifications clicked
Pushy.setNotificationClickListener(function (data) {
    // Display basic alert
    alert('Clicked notification: ' + data.message);

    // Navigate the user to another page or 
    // execute other logic on notification click
});

This method is now supported on both Android and iOS. Inside this method, you can then check the notification payload which was clicked and direct the user to the relevant page in your RN app.

To be able to access this method, please update the Pushy RN SDK by running the following commands in the root of your RN project:

npx react-native unlink pushy-react-native
npm install pushy-react-native@latest --save
npx react-native link pushy-react-native

Next, update the versions imported in android/app/build.gradle:

// Pushy SDK for Android
compile 'me.pushy:sdk:1.0.53'

// Pushy SDK for React Native Android
compile 'me.pushy:sdk-react-native:1.0.12'

Also, modify your Pushy.notify() invocation to include a third parameter:

Pushy.notify(notificationTitle, notificationText, data);

Good luck!

Elad Nava
  • 7,746
  • 2
  • 41
  • 61