Run code inside app when receiving push notification

I’m implementing push notifications in a Ionic 2 app for Android. For this, I’m using the following function:

registerPush() {
    this.push.register().then((t: PushToken) => {
        return this.push.saveToken(t, {ignore_user: false});
    }).then((t: PushToken) => {
        this.push.rx.notification().subscribe(msg => {
            // execute some code
        });
    });
}

With this, I’m able to receive push notifications sent from server. While the app is in foreground, the execute some code part is run without problems. While the app is in the background (I’m using the background plugin), the push notification is received, but when I click on it nothing happens.

I want to execute the notification code in this situation too, and open the app when I click it. Is there any way to achieve this?

1 Like