Wake up app from background

Hello guys,

I’m stuck in a problem and I’d like some suggestions on how to solve this.

I have a requirement to make the app wake up from background when a new order is received and start to play an alarm/sound until the order is accepted/rejected.

Currently, I’ve used background plugin with local notification to keep app opened in background, but the problem is to make the app wake up to achieve the goal.

Tried sending push notification from firebase but, unfortunately, I was not able to handle it in background for changing app to foreground. :frowning:

Tried all on the last ionic/capacitor version.

Any idea/suggestions is appreciated.

with a push notification you can get the “message” and only clicking on the notification the app will open.

Did you send data push notification? If so, this is handled by client and you need to send notification message which will be handled by OS and wake up the app. Then you can do what you need.


Notification message
FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys and an optional data payload of custom key-value pairs.

Data message
Client app is responsible for processing data messages. Data messages have only custom key-value pairs with no reserved key names.

Reference

That is the idea I was trying to test, sending with “data” to check whether the app was going to move to foreground and validate the user has not to tap on notification as @ciccilleju has commented.

Currently, capacitor official push notification seems to not handle background notifications as the old phonegap-plugin-push. Tried implementing both and also the new “havesource/cordova-plugin-push”, but I’m only able to receive notification from “notification” property which doesn’t work.

Do you have any plugin suggestion to achieve this or any example I can try to follow for handling background notifications?

Thanks for the answers guys!

check this:

Hey guys,

I was able to make it work and tested with the code above from @ciccilleju and it worked perfectly!
Thank you guys a lot for the help and to @ciccilleju for the code example.

I was getting crazy with this. :rofl:

Thanks!

Hi @carloshs , I have a similar requirement, but facing issues with “local notification”, means I was not able to receive any trigger to start local notification from push notification when the app is in the background. Can you help me on this?