# Power Management plugin not working ionic 2

**URL:** <https://forum.ionicframework.com/t/power-management-plugin-not-working-ionic-2/143694>\
**Category:** Ionic Native\
**Created:** [October 4, 2018, 2:25pm UTC](https://forum.ionicframework.com/t/power-management-plugin-not-working-ionic-2/143694 "2018-10-04T14:25:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrianpereira](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/adrianpereira/32/122031_2.png) [@adrianpereira](https://forum.ionicframework.com/u/adrianpereira)\
**Post date:** [October 4, 2018, 2:25pm UTC](https://forum.ionicframework.com/t/power-management-plugin-not-working-ionic-2/143694/1 "2018-10-04T14:25:48Z")

</div>

Hi, I’m using the plugin ionic native power-management with ionic v2, my intention is to not doze the app after 5 minutes in background (user is either looking at other app or just minimized). Here is my code:

_app.components.ts_

_import { BackgroundMode, BackgroundModeConfiguration } from ‘@ionic-native/background-mode’;_  
_import { PowerManagement } from ‘@ionic-native/power-management’;_  
_import { AndroidPermissions } from ‘@ionic-native/android-permissions’;_  
_import { Cordova } from ‘@ionic-native/core’;_

/_other libs/plugins_/

@Component({  
_templateUrl: ‘app.html’_  
_})_  
_export class GCEApp {_

_constructor(_  
_private backgroundMode: BackgroundMode,_  
_private powerManagement: PowerManagement,_  
_private androidPermissions: AndroidPermissions) {_  
_}_

public ngOnInit(): void {

```
this.translateService.setDefaultLang('pt-BR');

this.platform.ready().then(() => {
    
    this.hideSplashScreen();

    this.androidPermissions.requestPermissions([this.androidPermissions.PERMISSION.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS]);

    this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).then(
        result => console.log('Has permission REQUEST_IGNORE_BATTERY_OPTIMIZATIONS -> ',result.hasPermission),
        err => this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS));

    this.backgroundMode.enable();
    this.powerManagement.dim()
        .then((ok) => {
            console.log('PartialWakeLock enabled!');
            console.log(ok);
        })
        .catch((err) => {
            console.log('PartialWakeLock error!');
            console.log(err);
        });

    this.powerManagement.setReleaseOnPause(false)
        .then(ok => {
			console.log('setReleaseOnPause = false successfully');
			console.log(ok);
        }, function(err) {
			console.log('ERR setReleaseOnPause = false');
			console.log(err);
        });

});

```

}

The code above logs that I have permission to disable battery optimizations and that I acquired the partial wakelock with powerManagement.dim(), but after 5 minutes the app stops and only resumes if the user looks at the app again.

Testing with a Moto G2, Android v5.0.2.

Can somebody help? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![adrianpereira](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/adrianpereira/32/122031_2.png) [@adrianpereira](https://forum.ionicframework.com/u/adrianpereira)\
**Post date:** [October 23, 2018, 2:43pm UTC](https://forum.ionicframework.com/t/power-management-plugin-not-working-ionic-2/143694/2 "2018-10-23T14:43:45Z")

</div>

Solved the issue using this plugin instead of the ionic-native power management: [https://github.com/boltex/cordova-plugin-powermanagement](https://github.com/boltex/cordova-plugin-powermanagement)

With this I was able to keep running the app even after the screen faded.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:13pm UTC](https://forum.ionicframework.com/t/power-management-plugin-not-working-ionic-2/143694/3 "2021-07-19T21:13:46Z")

</div>

Closed on July 19, 2021, 9:13pm UTC


