How to receive Push but not the notification in tray using Ionic Framework?

I am using Ionic Framework for one of my project, I have successfully configured push notifications for both iOS and Android. Notifications are working the way they should.

I want the app to receive notification only if it is running and it is in foreground (I want to change some content in app when notification is received). And if app is in background or if it is not running I do not want app to receive a notification in tray or any message on screen.

It can be achieved in Native Development (like using Java for android) very easily, but can anyone help me solve my problem using Ionic?