# How to keep the screen awake

**URL:** <https://forum.ionicframework.com/t/how-to-keep-the-screen-awake/10031>\
**Category:** ionic-v1\
**Created:** [September 22, 2014, 6:54pm UTC](https://forum.ionicframework.com/t/how-to-keep-the-screen-awake/10031 "2014-09-22T18:54:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gaai](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@Gaai](https://forum.ionicframework.com/u/Gaai)\
**Post date:** [September 22, 2014, 6:54pm UTC](https://forum.ionicframework.com/t/how-to-keep-the-screen-awake/10031/1 "2014-09-22T18:54:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lrolecek](https://avatars.discourse-cdn.com/v4/letter/l/bc79bd/32.png) [@lrolecek](https://forum.ionicframework.com/u/lrolecek)\
**Post date:** [September 28, 2014, 11:16pm UTC](https://forum.ionicframework.com/t/how-to-keep-the-screen-awake/10031/2 "2014-09-28T23:16:47Z")

</div>

Get Insomnia plugin for Cordova.

> **[EddyVerbruggen/Insomnia-PhoneGap-Plugin](https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin)**
>
> Insomnia-PhoneGap-Plugin - :sleepy: Prevent the screen of the mobile device from falling asleep

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).

---

<div class="post-metadata">

**Author:** ![Gaai](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@Gaai](https://forum.ionicframework.com/u/Gaai)\
**Post date:** [September 29, 2014, 2:42pm UTC](https://forum.ionicframework.com/t/how-to-keep-the-screen-awake/10031/3 "2014-09-29T14:42:15Z")

</div>

Thank you! I will try this 🙂

---

<div class="post-metadata">

**Author:** ![Eusebe](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/eusebe/32/8144_2.png) [@Eusebe](https://forum.ionicframework.com/u/Eusebe)\
**Post date:** [December 18, 2014, 7:05am UTC](https://forum.ionicframework.com/t/how-to-keep-the-screen-awake/10031/4 "2014-12-18T07:05:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lrolecek](https://avatars.discourse-cdn.com/v4/letter/l/bc79bd/32.png) [@lrolecek](https://forum.ionicframework.com/u/lrolecek)\
**Post date:** [December 18, 2014, 8:01am UTC](https://forum.ionicframework.com/t/how-to-keep-the-screen-awake/10031/5 "2014-12-18T08:01:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Eusebe](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/eusebe/32/8144_2.png) [@Eusebe](https://forum.ionicframework.com/u/Eusebe)\
**Post date:** [December 18, 2014, 7:44pm UTC](https://forum.ionicframework.com/t/how-to-keep-the-screen-awake/10031/6 "2014-12-18T19:44:33Z")

</div>

I had several problems ; the first one was that I hadn’t done the [manual steps](https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin#manually) 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 !

---

<div class="post-metadata">

**Author:** ![peter1655](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/peter1655/32/92203_2.png) [@peter1655](https://forum.ionicframework.com/u/peter1655)\
**Post date:** [October 8, 2015, 2:59pm UTC](https://forum.ionicframework.com/t/how-to-keep-the-screen-awake/10031/7 "2015-10-08T14:59:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![icrievrytim](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/icrievrytim/32/101217_2.png) [@icrievrytim](https://forum.ionicframework.com/u/icrievrytim)\
**Post date:** [June 20, 2016, 1:55pm UTC](https://forum.ionicframework.com/t/how-to-keep-the-screen-awake/10031/8 "2016-06-20T13:55:26Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![micrdy](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@micrdy](https://forum.ionicframework.com/u/micrdy)\
**Post date:** [July 21, 2016, 1:37pm UTC](https://forum.ionicframework.com/t/how-to-keep-the-screen-awake/10031/9 "2016-07-21T13:37:56Z")

</div>

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