0

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.
Arun Girivasan
  • 532
  • 1
  • 10
  • 24

1 Answers1

0

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.

rtpHarry
  • 13,019
  • 4
  • 43
  • 64
  • Thanks for reply rtpHarry. I tested my app with Lenovo vibe p1m, not in browser.I have a doubt, you said some chinese android handsets do special things to disable background power drain. if my phone have some thing like that, then how whatsapp and facebook shows notification in this phone if the app is in background? – Arun Girivasan Jun 22 '19 at 13:44
  • How can i do that with ionic? Is there any other option to show notification if the app is in background? – Arun Girivasan Jun 22 '19 at 13:46
  • not working.But i found that plugin is not correctly installed.But the plugin shows in project plugins folder – Arun Girivasan Jun 22 '19 at 14:55
  • 'ionic cordova plugin add cordova-plugin-background-mode --verbose' i used this command to install then i saw a cordovaError: warn node_modules\cordova-lib\src\plugman\install.js at Array.forEach () – Arun Girivasan Jun 22 '19 at 14:59
  • i fix the problem. downgraded cordova cli version. and reinstalled plugin – Arun Girivasan Jun 22 '19 at 16:45