How to keep the screen awake

I want to add a setting to my app that users can use to keep the screen awake while using the app.
Is this possible, and if, how?
Thanks in advance.

1 Like

Get Insomnia plugin for Cordova.

Works perfectly in my app. It’s a fitness timer so I want to keep screen always on when timer is running during the exercise but I allow it to be turned off anywhere else in the app (when user’s just browsing menus).

1 Like

Thank you! I will try this :slight_smile:

Hi,

How do you do your call to keepAwake() function ?
I tried as follows, but it doesn’t work:

<button class="button button-royal" ng-click="$window.plugins.insomnia.keepAwake();">keep awake</button>

Obviously I checked that the plugin is my generated apk.

Just window.plugins.insomnia.keepAwake(); No $ at the beginning.

I had several problems ; the first one was that I hadn’t done the manual steps of the install (I’m still wondering if it should be either the automatic or the manual part, or both are required ; first I thought “cordova prepare” would do everyrthing needed).
Now it works, thanks !

I had similar problem and here are my remarks, maybe they will save someone’s time:
I installed cordova-plugin-insomnia by running these two commands:

$ cordova plugin add https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git
$ cordova prepare

And tried this button:

 <button onclick="window.plugins.insomnia.keepAwake();">keep awake</button>

On my pc (via ionic serve) clicking the button fails with

Uncaught TypeError: Cannot read property 'insomnia' of undefined

As I found out, the plugin works only on real hardware (smartphone), not in browser mode on PC - which is obvious now (and makes sense after all), but would be nice if the author would mention it in plugin description.

There is no need to install the plugin via the manual steps, it works well when installed via cordova.

Hello everyone,

Does someone knows if this plugin insomnia, works on the app “Ionic view” ?

Or i need to install it directly on my device ?

Thanks a lot :slight_smile:

Have you tested this already? I don´t think so.