EddyVerbruggen / Insomnia-PhoneGap-Plugin

:sleepy: Prevent the screen of the mobile device from falling asleep

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it working with Ionic4?

ioclaudio opened this issue · comments

Hi,
I'm using Insomnia on a Ionic4 app in this way:
`

if (this.platform.is('cordova')) {
  this.insomnia.keepAwake()
    .then(
      (res) => {
        console.log(`'@ allowSleepAgain --> success'`);
      },
      (err) => {
        console.log('@ allowSleepAgain --> ERROR');
      }
    );
}

`
Running the appon a Xiomi Redmi4 (in debug mode) I can see that the app prints:
'@ allowSleepAgain --> success'

However, the cell phone still sleeps after some minutes.
Which could be the problem?
Is there a way to debug the problem?

I have these plugin installed:
`

cordova.cmd plugin ls
cordova-plugin-camera 4.0.3 "Camera"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
cordova-plugin-insomnia 4.3.0 "Insomnia (prevent screen sleep)"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 3.1.2 "cordova-plugin-ionic-webview"
cordova-plugin-mauron85-background-geolocation 3.0.3 "CDVBackgroundGeolocation"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
phonegap-plugin-barcodescanner 8.0.1 "BarcodeScanner"`

`

Ionic:
Ionic CLI : 5.0.0
Ionic Framework : @ionic/angular 4.3.0
@angular-devkit/build-angular : 0.13.8
@angular-devkit/schematics : 7.2.4
@angular/cli : 7.3.8
@ionic/angular-toolkit : 1.4.1
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.0.0, ios 5.0.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 10 other plugins)
`

Hi, any solution to this?

@BrendanThysse have you found a solution ?

@AlfredMothapo the issue on my side was due to where I allow for the app to sleep again, I had different scenarios where I need to keep the screen on and based on that where I allow the screen to sleep after some processing. There were some issues in my code execution that led to the problem, solved it by reevaluating where I need to keep the screen on. Hope you find your solution as the plugin is working fine for me. 🙂

@Brendan92 confirming it works well too in my case, but when I build the signed APK, the plugin stops working. Do you know why is that? Have you had the same problem? In brief, all good while debugging, but then when the build is ready for the app store, it doesn't work anymore... Thx

@albansch I have unfortunately not experienced this kind of behavior on my side, works the same when developing as well as when deployed to app store/play store. Hope you find the solution sorry for not being much help.

@BrendanThysse thx for the feedback. I actually found the root cause of my issue: within the gradle.build, I set minifyEnabled to true, and it broke the class names. Reverting back to minifyEnabled to false made it work fine.