How to get a Capacitor app to run in the background on Android

I have a VueJS app that continuously records from the microphone and then every 30 seconds it sends the prior 30 seconds of recordings to my server. I need this app to continue to do this even when Android puts it in the background.

As a PWA, when the app is put in the background, it continues to record audio, but it stops sending the audio to the server. I don’t know why it stops sending.

I tried addressing this by wrapping my app in Capacitor and adding GeoLocation and requesting the location every couple of minutes. I built an APK and installed it. I also used android settings to configure my app to not optimize battery life. That should allow it to run continuously in the background.

Unfortunately, Android still puts my app in the background and it stops sending the files to the server every 30 seconds.

Does anyone know how I can fix this? Otherwise, I have to abandon my VueJS/Capacitor app and write it in Java. :frowning:



The documentation says you must set the display or it could still put you to sleep.

    enableBackground() {
            text: "Recording",
            title: "Running",
            icon: "background_icon",


Then you could create an observable to send at intervals

    saver: Observable<number> = timer(0, 30 * 1000);

            this.saver.subscribe(async (counter) => {