Search code examples
javascriptcordovaphonegap-pluginscordova-plugins

cordova plugin won't work


I've installed a Cordova plugin. Everything went succesfull, until I tried to use the plugin. I only need the plugin to work for Android. This is the plugin I'm trying to use:

http://plugins.cordova.io/#/package/net.yoik.cordova.plugins.screenorientation

I do see the plugin is installed into my directory (plugins --> net.yoik.cordova.plugins.screenorientation).

My javascript code:

window.onload = function () {

// access current orientation
console.log('Orientation is ' + screen.orientation);

screen.lockOrientation('portrait');

// access current orientation
console.log('Orientation is ' + screen.orientation);
};

The console.log shows 'undefined'.

My config.xml file:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.hello"
    version="0.0.1"
    xmlns="http://www.w3.org/ns/widgets"
    xmlns:gap = "http://phonegap.com/ns/1.0"
    xmlns:cdv="http://cordova.apache.org/ns/1.0">


<name>Shoot Out</name>

<author email="[email protected]" href="http://cordova.io">
    Apache Cordova Team
</author>

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

<!-- Customize your app and platform with the preference element. -->
<preference name="orientation"                value="default" />
<preference name="target-device"              value="universal" />
<preference name="fullscreen"                 value="false" />  
<preference name="webviewbounce"              value="false" /> 
<preference name="prerendered-icon"           value="true" />
<preference name="stay-in-webview"            value="true" />
<preference name="ios-statusbarstyle"         value="black-opaque" />
<preference name="detect-data-types"          value="true" />  
<preference name="exit-on-suspend"            value="false" /> 
<preference name="show-splash-screen-spinner" value="true" />  
<preference name="auto-hide-splash-screen"    value="true" />     
<preference name="disable-cursor"             value="false" />   
<preference name="android-minSdkVersion"      value="7" />     
<preference name="android-installLocation"    value="auto" />

<!-- Plugins -->
<gap:plugin name="net.yoik.cordova.plugins.screenorientation" version="1.3.1" />
<access origin="*" />

My index file:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="format-detection" content="telephone=no"/>
<meta name="msapplication-tap-highlight" content="no"/>
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<!--<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=4, maximum-scale=1, minimum-scale=1, height=device-height, target-densitydpi=device-dpi" />-->
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, target-densitydpi=low-dpi, user-scalable=0"/>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>

<!-- FIREBASE CONNECTION -->
<script src="https://cdn.firebase.com/js/client/2.0.4/firebase.js"></script>

<script src="js/getCurrentGames.js"></script>
<script src="js/main.js"></script>
<title>Groot Project</title>
</head>
<body>
<div id="all"></div>
</body>
</html>

I've tried it on my pc and my phone (android), both with the same error. Any idea?


Solution

  • I fixed it by adding this:

    <script type="text/javascript" src="cordova.js"></script>
    

    to my index.html