Reputation: 1
I need the app to run fully in the background and when I use other apps on my phone. The program transmits video from the camera. When I turn off the screen, I managed to get the program to transmit video, but when I turn on other programs on the phone, the program stops transmitting. Part of the code as I managed to omit in off mode. i use library @ionic-native/background-mode
componentDidMount() {
document.addEventListener('deviceready', () => {
BackgroundMode.setEnabled(true);
BackgroundMode.disableBatteryOptimizations();
BatteryStatus.onChange().subscribe(status => {
this.batteryStatus = status;
this.signalCurrentStatus();
});
},false);
Upvotes: 0
Views: 100
Reputation: 348
Use plugin Background Mode
ionic cordova plugin add cordova-plugin-background-mode
npm install @ionic-native/background-mode
Then use it like this:
import { BackgroundMode } from '@ionic-native/background-mode/ngx';
export class AppComponent {
constructor(private backgroundMode: BackgroundMode) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.backgroundMode.enable();
});
}
}
Upvotes: 0