EddyVerbruggen / Insomnia-PhoneGap-Plugin

:sleepy: Prevent the screen of the mobile device from falling asleep
264 stars 104 forks source link

Plugin not working on some devices #41

Open rex79 opened 7 years ago

rex79 commented 7 years ago

Hi, is there a settings on android that will prevent the plugin from work? I've try with different device and I put this code on my app.component.ts:

platform.ready().then(() => { // Okay, so the platform is ready and our plugins are available. // Here you can do any higher level native things you might need. Splashscreen.hide(); StatusBar.styleDefault();

  Insomnia.keepAwake().then(
    () => console.log('non dormo'),
    () => console.log('errore, dormo')
  );

(I'm using ionic 2) and on some device it work, on other no.

Is this the right way to call it or there are some sort of Android settings that will block the plugin?

Thanks a lot

okandeb commented 7 years ago

+1

nimeso commented 7 years ago

Same issue with ionic 2, I have: app.module.ts:

import { Insomnia } from '@ionic-native/insomnia';

providers: [
  Insomnia,
]

export class AppModule {
   constructor(private backgroundMode: BackgroundMode, public platform: Platform, private insomnia: Insomnia) { 
        console.log('Hello app');
        this.platform = platform;
        this.platform.ready().then(() => {
            this.backgroundMode.enable();
            this.insomnia.keepAwake()
              .then(
                () => console.log('success'),
                () => console.log('error')
              );
        });
   }
}

But after 40secs the app goes to sleep and it fails. Client is freaking! Using Remi note 4 with Android version 5.0.2. No errors in any logs... just seems to stop. please help

nimeso commented 7 years ago

+1 one, about to get my head chopped off, happy to pay for your time to help asap

nimeso commented 7 years ago

DId anyone have any luck with this. It's really driving me insane, not to mention getting yelled at by the client. Are we doing this right? Should the code go in app.module.ts.... So confused

EddyVerbruggen commented 7 years ago

@nimeso You client is a dick.

Have you tried calling keepAwake in a different spot of your app to make sure the timing is right? For instance on a home screen, triggered from a button, for experiment's sake?

AgDude commented 7 years ago

I can confirm that we are running into this as well. I will investigate in more detail later today. The device I confirmed this on was Galaxy S5 with Android 6.0.1 and webview version 60.0.3112.107

edit: See comment below. This was not a bug in insomnia.

Jun711 commented 7 years ago

For me, it works on development mode but not on production mode. What could be the possible causes? the device is an iphone 5.

EddyVerbruggen commented 7 years ago

@Jun711 How are those modes different? Also stuff like Webpack?

Jun711 commented 7 years ago

@EddyVerbruggen Yea, there is webpack. And I built it with this command ionic prepare ios --prod --release

the browser is Mobile Safari UIWebView ver 10.3.3

EddyVerbruggen commented 7 years ago

Perhaps webpack messes it up, perhaps something else, but you need to do the digging.

AgDude commented 7 years ago

I can confirm that my problem was in our own code. Insomnia is working for us as it should (and has for years). Thanks Eddy.

Jun711 commented 7 years ago

@AgDude hi, could you please briefly explain what problem u ran into? Thanks!

AgDude commented 7 years ago

The short answer is that we were calling "allowSleep" immediately after calling "keepAwake".

We manage insomnia with a service that gets tied into which view is active, as well as what long-running async functions may be running and try to handle it automatically. That service was broken and letting an async function cancel the keepAwake when it shouldn't.

nimeso commented 7 years ago

@EddyVerbruggen Bhahahaha. Unfortunately my client is a good friend of mine :) Poor bastard has gone through 5 devs on this project and it was suppose to be completed in 3 months... 6 months later... haha. I'll try a manual button. And let you know how it goes :) It should work in platform ready though?

nimeso commented 7 years ago

Ok, so I'm calling keepAwake() on a manual button now but still have the same issue. Issue.

  1. If the app is selected and running in the background eg: hit the home button to background all apps.
  2. it works for about 40secs and then the phone sleeps and it stops working BUT
  3. don't hit the phones home button and it goes to sleep but still works. Basically it only works if I let the app stay open in foreground and then phone sleeps. If the app is in the background and phone sleeps it fails. Thoughts? Is anyone else seeing this?
nimeso commented 7 years ago

I have a feeling this is a security issue?

nimeso commented 7 years ago

Ok, this is getting nuts @EddyVerbruggen . This plugin does not work :( what am I doing wrong? I've put in in home page, I've put it in a button... I've done everything! After 40sec it just stops working when the phone goes to sleep. Happy to help pay for your time, this is getting urgent. I can add you to our Ionic repo and maybe you can look. I've wasted 3 days now. Desperate for help.

EddyVerbruggen commented 7 years ago

@nimeso If you can start a new cordova create myapp helloworld app and reproduce the issue there (and share the project), I will take a look.

nimeso commented 7 years ago

@EddyVerbruggen Thanks man! I'm going to have a long needed day away from this stupid computer today :) but I'll do that tonight. I made some discoveries yesterday though. Your plugin does work. But it's the background-geolocation that seems to stop working, everything else works fine in sleep mode. I've discovered if you change the battery saving settings on your android everything works fins including the geolocation. :) My fingers are slow at typing... they need coffee. Thanks for all your help.

tlajer commented 5 years ago

I see that this is an old issue. Im facing something similar though.

The plugin works flawless on all our test devices. However, our client has bought a bunch of Huawei phones for their staff - and all of these phones fails.

They are using the following devices: FIG-LX1 ALE-L21