cordova-plugin-background-mode: Background mode not working on Android 8.0.0. Working on earlier versions
Test Environment:
- Android 8.0.0
- Phone: Galaxy S9+
- Samsung experience version 9.0
- Background Mode Version: cordova-plugin-background-mode 0.7.2 “BackgroundMode”
- Cordova Android Version: 6.4.0
- npm install output:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
- Battery optimization disabled.
Symptoms:
- Phone sleeps, fails several minutes after working in background
- Notification is not showing up for backgroundmode
- Logging the output of isEnabled(), I get an empty result (at least console.log doesn’t show anything).
I’m happy to do any debugging or additional information that might help.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 8
- Comments: 136
Commits related to this issue
- REQUEST_IGNORE_BATTERY_OPTIMIZATIONS needs to be added manually — committed to katzer/cordova-plugin-background-mode by katzer 5 years ago
Thanks a lot @JuneTwooo, @nadimnakade Is working great 😃 and spending much less battery and less plugins. ( with the power Management plugin was more battery consuming .)
I don’t send the local notification, I set the sticky in the default options and working !!! 😃
I set id=-1 because I am also sending some normal notifications not sticky with id>=0 and would replace this sticky one
I implemented this as an ionic provider. I’ve attempted to clean up my code for general use below, but I haven’t verified this version. My version is very similar…
` import { Injectable } from ‘@angular/core’; import { BackgroundMode } from ‘@ionic-native/background-mode’; import { Platform } from ‘ionic-angular’; import { PowerManagement } from ‘@ionic-native/power-management’;
@Injectable() export class backgroundProvider {
} `
I’ve seen this: https://altbeacon.github.io/android-beacon-library/foreground-service.html
so Android versions 8+ restrict services from running in the background to only 10 minutes after an app leaves the foreground.
… so the alternative is to use a foreground service: A foreground service is differs from regular Android background services in that it shows a persistent notification showing your app icon and configurable text.
… I’m looking for a Cordova Plugin that manage the foreground service if Android 8+ or background service if Android < 8.
@TheMoroccan09 It is working now in my Xiaomi 7.1.1 and not working in my cliente Galaxy S10+ 9 You can check the solutions for your mobile clicking in the corresponding icon here https://dontkillmyapp.com
It only works if device is plugged in power cable. I don’t know why this happens…
Use this plugin and solved all problem =>
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/
APP NAME keeps stopping when background mode is active. APP crashes.
https://github.com/katzer/cordova-plugin-local-notifications (with sticky: true) like that :
cordova.plugins.notification.local.schedule( { title: ‘my app’, text: ‘my text’, icon: ‘file://icon.png’, smallIcon: ‘res://icon.png’, sticky: true, foreground: true });
Possible fix for some of you: https://github.com/katzer/cordova-plugin-background-mode/pull/435
I’m still on this solution…
Use this to keep app running when phone goes into (Android 6+) doze/standby mode.
https://github.com/thomas550i/cordova-plugin-doze-Optimize/
Hey Everyone,
I think this fork is working better. https://github.com/tushe/cordova-plugin-background-mode
Finally I was able to make it work for longer time.
I came across this solution mixing power management, partial wake-locks, and background mode: https://forum.ionicframework.com/t/i-found-a-solution-for-some-regular-background-activity/27012
Seems to do the trick for the samsung s9…