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

Not available in Samsung Galaxy S3

jalbam opened this issue · comments

Hi,

I am using Insomnia 3.0 with PhoneGap 3.3.0. The following code always fire the catch error ("fatal error for insomnia"):

try
{
    window.plugins.insomnia.keepAwake(function(){alert("Insomnia!");}, function(){alert("insomnia failed!");});
} catch (e) { alert("fatal error for insomnia!"); }

And this is always false:
if (typeof(window.plugins) !== "undefined" && typeof(window.plugins.insomnia) !== "undefined" && typeof(window.plugins.insomnia.keepAwake) !== "undefined")

I also tried to execute the code with an onClick event of a button instead of body's onLoad with no success.

I am using PhoneGap Build through web interface and in Plugins it detects Insomnia as installed:

Third Party VERSION LATEST VERSION
nl.x-services.plugins.insomnia 3.0 3.0

This is my config.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns   = "http://www.w3.org/ns/widgets"
    xmlns:gap   = "http://phonegap.com/ns/1.0"
    id          = "yasminoku"
    versionCode = "69"
    version     = "0.29a" >

<!-- versionCode is optional and Android only -->

<preference name="phonegap-version" value="3.3.0" />

<name>Yasminoku</name>

<content src="index.html" />
<access origin="*" />

<icon src="icon.png" />
<gap:splash src="splash.png" />

<preference name="permissions" value="none"/>

<description>
    Yasminoku is a sudoku game, generator and solver created by Joan Alba Maldonado on 25th of July 2006 which has been now improved and adapted to mobile devices.
</description>

<author href="https://www.granvino.com" email="granvino@granvino.com">
    Joan Alba Maldonado
</author>

<preference name="orientation" value="default" />        <!-- all: default means both landscape and portrait are enabled -->
<preference name="target-device" value="universal" />      <!-- all: possible values handset, tablet, or universal -->
<preference name="fullscreen" value="true" />           <!-- all: hides the status bar at the top of the screen -->
<preference name="prerendered-icon" value="true" />           <!-- ios: if icon is prerendered, iOS will not apply it's gloss to the app's icon on the user's home screen -->
<preference name="ios-statusbarstyle" value="black-opaque" />   <!-- ios: black-translucent will appear black because the PhoneGap webview doesn't go beneath the status bar -->
<preference name="detect-data-types" value="false" />           <!-- ios: controls whether data types (such as phone no. and dates) are automatically turned into links by the system -->
<preference name="exit-on-suspend" value="false" />          <!-- ios: if set to true, app will terminate when home button is pressed -->
<preference name="auto-hide-splash-screen" value="true" />           <!-- ios: if set to false, the splash screen must be hidden using a JavaScript API -->
<preference name="disable-cursor" value="false" />          <!-- blackberry: prevents a mouse-icon/cursor from being displayed on the app -->
<preference name="android-minSdkVersion" value="7" />              <!-- android: MIN SDK version supported on the target device. MAX version is blank by default. -->
<preference name="android-installLocation" value="auto" />           <!-- android: app install location. 'auto' will choose. 'internalOnly' is device memory. 'preferExternal' is SDCard. -->

<gap:plugin name="nl.x-services.plugins.insomnia" version="3.0" />

Thank you in advance.

Cheers,
Joan

Sorry, I answer myself:

Reading the documentation of Insomnia which says "The required javascript file is brought in automatically. There is no need to change or add anything in your html." I thought I didn't have to add anything, but after adding the following line to my index.html now it works properly:

<script src="phonegap.js"></script>

Without that line my project still worked with PhoneGap Build but not the Insomnia plugin. I didn't need to add <script src="js/plugins/Insomnia.js"></script> at all.