0
votes

I installed cordova background mode plugin by these commands

ionic cordova plugin add cordova-plugin-background-mode
npm install @ionic-native/background-mode

in app.module.ts i imported like this

import { BackgroundMode } from '@ionic-native/background-mode/ngx';

and added in providers array.

my page.component.ts

    constructor(private pltfm: Platform, private backgroundMode: BackgroundMode) { }
ngOnInit() {
    this.pltfm.ready().then(() => {
          this.backgroundMode.on('activate').subscribe(() => {
            console.log('activated');
          });

 this.backgroundMode.enable();
    });
    }

I got backgroundMode Plugin not installed error while running the app.How can i fix this problem?

Native: tried calling BackgroundMode.enable, but the BackgroundMode plugin is not installed.
1

1 Answers

0
votes

Brainstorming

It seems like you are doing this correctly.

Are you testing it on a browser? Is it a decent phone?

I've read somewhere that the cheap Chinese android handsets are underpowered and do special things to disable this sort of background power drain.

The docs say that Browser is a supported platform but some discussion of the plugin that I've found says that it's buggy. Are you testing it on an actual device?

Ensure you have matching versions

From doing some more research into this it seems one cause might be that you setup your platform a while ago, but added the plugin recently.

This can result in your version of cordova being out of date as when you add the plugin it installs its latest version which could require a more updated version of cordova.

If that's your problem the simple solution is to run these commands:

ionic cordova platform remove android
ionic cordova platform add android

However, a more detailed answer is here.