cordova-plugin-background-mode icon indicating copy to clipboard operation
cordova-plugin-background-mode copied to clipboard

IONIC App is not placed in Foreground

Open marcosjara opened this issue 3 years ago • 4 comments

Hello boys,

First of all thanks for this plugin, it is very useful,

I have a problem, but I really don't know if it is this plugin that has to solve it, or the solution is achieved by another plugin

My application is developed in Ionic 4

The process is as follows: For video calling functionality, I send a high priority fcm notification to the recipient. The recipient receives the notification, an audio sounds and activates a screen where the user can answer or cancel the call, using the following commands:

this.backgroundMode.enable (); this.backgroundMode.moveToForeground (); this.backgroundMode.wakeUp (); this.backgroundMode.unlock ();

The APP works without problems as I wish when on my Smartphone, I leave "My Application" as the last application used, that is, the app is put in the foreground and the screen is displayed for the user to answer the call, even if the user has left to use your phone for more than 15 minutes.

The problem is when the user has used other applications, before his phone has been blocked, for example, the user navigated through my application, but then he went to Facebook, or WhatsApp, then he no longer used his phone so later after a few seconds your phone is locked.

At that moment when the origin makes a video call to the recipient, the phone receives the notification also without problems, even the Audio that I put on it sounds, but the plugin does not manage to unlock the phone and show the page to answer or cancel, it is as if it were that there is another application on top and that is why the application cannot be put in the foreground.

I hope you have understood me and I hope you can help me.

Greetings and thanks

marcosjara avatar Sep 26 '20 03:09 marcosjara

You must add this line to AndroidManifest.xml:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

felinuxsas avatar Dec 04 '20 02:12 felinuxsas

@marcosjara I know it's a bit old, but any hint on this? I'm facing the same problem. My application has the ability to make videocalls but if I suddenly move it to the background and open up, for example, Google Chrome on top of it, I make the call to the phone but the application no longer goes in the foreground.

I'm able to hear the sound from the incoming call but the application doesn't move to the foreground, it stays behind any application is in the front at the time the user is using his phone. Did you manage to find a proper solution to this? The plugin works great if you leave the application in the background though (this is not fully closing it).

On the other hand, if you kill the application completely the plugin stops working, needing to open up your app if you want to know you have an incoming call. PS I have the FOREGROUND_SERVICE permission in the AndroidManifest file as well.

nahuelleiva avatar Feb 05 '21 18:02 nahuelleiva

hi,
I am also facing the same issue any help?

nikhilhoum avatar Feb 20 '21 12:02 nikhilhoum

Hi,

You have to add FOREGROUND_SERVICE permission in your app.

This must be included in the plugin but unfortunately it is not.

Add those lines to your config.xml to grant the missing permission, this should fix the issue:

<config-file parent="./" target="app/src/main/AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> </config-file>

Happy coding day!

karimslim avatar Jun 04 '21 09:06 karimslim