cordova-plugin-background-mode
cordova-plugin-background-mode copied to clipboard
Application automatically goes to foreground
I just installed the latest version of the plugin as I had issue with running on background for longer time. It works perfect now. Unfortunately I experience new issue - when I switch to another application, my application goes automatically to foreground after couple of seconds. Repeating switching to another application helps, but the user experience is terrible. I experience this on Android 8 and 9 ( I haven't tested another one ). Plugin initiation is:
cordova.plugins.backgroundMode.onactivate = function() {
cordova.plugins.backgroundMode.disableWebViewOptimizations();
cordova.plugins.backgroundMode.disableBatteryOptimizations();
};
cordova.plugins.backgroundMode.ondeactivate = function() {};
cordova.plugins.backgroundMode.onfailure = function(errorCode) {};
cordova.plugins.backgroundMode.setDefaults({
title: "My title",
text: ""My text,
icon: 'icon'
});
cordova.plugins.backgroundMode.enable();
@mstrop: Are you not facing the same issue https://forum.ionicframework.com/t/backgroundmode-not-installing-cordova-9/160226/5 ?
@mstrop: Are you not facing the same issue https://forum.ionicframework.com/t/backgroundmode-not-installing-cordova-9/160226/5 ?
No, my issue has nothing to do with the installation. The plugin is installed and it's working as expected. The issue is, that when my application starts running on background, it goes unexpectedly to foreground after couple of seconds.
I use Cordova 8.1.2
Okay thank you @mstrop
I had the same issue. Adding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission solved it.
The problem (I think) is that disableBatteryOptimizations() needs this permission whereas it is not specified in plugin.xml.
You can still add it by yourself in your config.xml:
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
</config-file>
</platform>
@mstrop : are you fixed above issue?
@mstrop : are you fixed above issue?
I have moved to another plugin in mean time. Sorry, I haven't closed the issue.
@mstrop : which plugin u have used sir?
https://github.com/transistorsoft/cordova-background-geolocation-lt
https://github.com/transistorsoft/cordova-background-geolocation-lt
this plugin have to pay or free sir?