If someone need this, the solution that work for me was use the "@ionic-native/background-mode" plugin.
The resolution for this problem it's pretty easy actually. No need for intent, just install the '@ionic-native/background-mode'.
For Ionic 3, install the plugin using this command:
ionic cordova plugin add cordova-plugin-background-mode
npm install --save @ionic-native/background-mode@4
File: app.module.ts:
import {BackgroundMode} from "@ionic-native/background-mode";
Add on providers:
providers: [
BackgroundMode,
...
],
File: app.component.ts:
Import the background-mode plugin:
import {BackgroundMode} from "@ionic-native/background-mode";
Add on constructor
constructor(
platform: Platform,
statusBar: StatusBar,
splashScreen: SplashScreen,
...
private backgroundMode: BackgroundMode) {
this.backgroundMode.enable();
this.backgroundMode.excludeFromTaskList();
this.backgroundMode.overrideBackButton();
// this.backgroundMode.setDefaults({silent: true});
this.backgroundMode.on('activate').subscribe(value => {
this.backgroundMode.disableWebViewOptimizations();
});
}
File: fcm.ts
Here is where all Firebase notification are. First, import the background-mode:
import {BackgroundMode} from "@ionic-native/background-mode";
Now, we just call these two functions on onNotificationOpen, which is the function that firebase call when notification arrives:
listenToNotifications() {
return this.firebaseNative.onNotificationOpen()
}
this.listenToNotifications().subscribe(
((msg: any) => {
// 'These two functions make the magic'
this.backgroundMode.unlock();
this.backgroundMode.moveToForeground();
if (!msg.tap)
this.events.publish(this.dataInfo.eventFcmNew, msg)
else
this.events.publish('push', 'NotificationsPage')
})
)
That's it!
Git Example