0

当我在手机上使用其他应用程序时,我需要该应用程序在后台完全运行。该程序从摄像机传输视频。当我关闭屏幕时,我设法让程序传输视频,但是当我打开手机上的其他程序时,程序停止传输。我设法在关闭模式下省略了部分代码。我使用库@ionic-native/background-mode

  componentDidMount() {
    document.addEventListener('deviceready', () => {
      BackgroundMode.setEnabled(true);
      BackgroundMode.disableBatteryOptimizations();
      BatteryStatus.onChange().subscribe(status => {
        this.batteryStatus = status;
        this.signalCurrentStatus();
      });
    },false);
4

1 回答 1

0

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();
        });
    }
}
于 2020-07-15T21:40:19.047 回答