Rectangle 27 14

Error states that google is undefined. My best educated guess would be that the script from the index.html is not loaded correctly:

<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyD4bzp0Ck8nTXgfs9ZYo8vXZ2tgWhqzWmY&sensor=true">

I think this is because of the new Cordova 5.0 release being used. You need to install the cordova-plugin-whitelist as following:

cordova plugin add cordova-plugin-whitelist

Also add the following to config.xml:

<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="*" />
index.html
<meta http-equiv="Content-Security-Policy" content="default-src 'self' *; style-src 'self' 'unsafe-inline' *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *">

Be aware that above settings are not settings you want to have in a production environment. Please take a look at the README of the cordova-plugin-whitelist to learn more.

Sorry bro tried it but it shows a white screen without the map. No change tried what you wrote here. Got the same problem in ios emulate too

Hey wait just changed the placement of the script tag and played with the css. It has started working thanks btw though1

hello did you find a solution for that ?? i have the same issue

Google Maps on Ionic Framework/Cordova not working on android build - ...

cordova ionic-framework phonegap-plugins cordova-plugins
Rectangle 27 3

The essence of the problem is that so long as cordova.device is undefined, your code can't be sure if that's because cordova has established that your device is not supported, or if it's because cordova is still preparing itself and deviceready will fire later (or third option: cordova didn't load properly).

The only solution is to define a waiting period, and to decide that after this period your code must assume the device is not supported. I wish cordova would set a parameter somewhere to say "We've tried finding a supported device and given up" but it seems like there is no such parameter.

Once this is established, you may want to do something specific precisely in those situations where there is no supported device. Like hiding links to the device's app market, in my case.

I've pieced together this function which should cover pretty much every situation. It lets you define a deviceready handler, a device-never-ready handler, and a waiting time.

//Deals with the possibility that the code will run on a non-phoneGap supported
//device such as desktop browsers. Gives several options including waiting a while
//for cordova to load after all.
//In:
//onceReady (function) - performed as soon as deviceready fires
//patience 
//  (int) - time to wait before establishing that cordova will never load
//  (boolean false) - don't wait: assume that deviceready will never fire
//neverReady 
//  (function) - performed once it's established deviceready will never fire
//  (boolean true) - if deviceready will never fire, run onceReady anyhow
//  (boolean false or undefined) - if deviceready will never fire, do nothing
function deviceReadyOrNot(onceReady,patience,neverReady){

    if (!window.cordova){
            console.log('Cordova was not loaded when it should have been')
            if (typeof neverReady == "function"){neverReady();}
        //If phoneGap script loaded...
        } else {
            //And device is ready by now...
            if  (cordova.device){
                callback();
            //...or it's loaded but device is not ready
            } else {
                //...we might run the callback after
                if (typeof patience == "number"){
                    //Run the callback as soon as deviceready fires
                    document.addEventListener('deviceready.patience',function(){
                        if (typeof onceReady == "function"){onceReady();}
                    })
                    //Set a timeout to disable the listener
                    window.setTimeout(function(){
                        //If patience has run out, unbind the handler
                        $(document).unbind('deviceready.patience');
                        //If desired, manually run the callback right now
                        if (typeof neverReady == 'function'){neverReady();}
                    },patience);
                //...or we might just do nothing
                } else {
                    //Don't bind a deviceready handler: assume it will never happen
                    if (typeof neverReady == 'function'){neverReady();} 
                    else if (neverReady === true){onceReady();} 
                    else {
                       //Do nothing
                    }
                }
            }
    }

}

javascript - PhoneGap: Detect if running on desktop browser - Stack Ov...

javascript cordova
Rectangle 27 4

If you closely observe the LogCat log, you will notice that there is an error in "downloader.js" file. It is made for older version of phonegap. I was searching a lot how to fix the same problem as yours but I only found your question posted here. So, the bottom line is that we'll have to fix the syntax in the script file. Those morons changed whole syntax without care of backward compatibility :(

In order to make the code working, replace the downloader.js code with this:

/* downloader.js */
function Downloader() {}
    Downloader.prototype.downloadFile = function(fileUrl, params, win, fail) {

    //Make params hash optional.
    if (!fail) win = params;
       cordova.exec(win, fail, "Downloader", "downloadFile", [fileUrl, params]);
};

if(!window.plugins) {
    window.plugins = {};
}
if (!window.plugins.Downloader) {
    window.plugins.Downloader = new Downloader();
}

And next, the call should be:

window.plugins.Downloader.downloadFile(url, {dirName: contentDirectory, fileName: someFileName, overwrite: true},
             function(data){
                 if(data=="exist"){
                  /// alert("File already exist");
                     console.log("File allready exist!");
                 }
                 else{
                     console.log("Status: " + data.status);
                 }
             },
             function(data){
                 console.log("error: "+data); 
             }
     );

I'm writing this after all night without sleep. There is no need for upload and download plugins, they implemented this in v. 2.1.0, please see their documentation. Another thing... it will not work with self-signed certificate!

cordova - android/phonegap Uncaught TypeError: Cannot read property 'd...

android cordova phonegap-plugins
Rectangle 27 2

For me, it was the same symptom (Media undefined) but from a different problem (missing Media plugin). I had to run this command:

cordova - phonegap: Uncaught ReferenceError: Media is not defined - St...

cordova
Rectangle 27 3

Anybody who runs into the above error message after update of either nodejs, npm or (especially) cordova.

The solution was to create a fresh cordova project using cordova create <projectname> and then install the plugins and platforms that you are building for.

The next step is to copy over the config.xml preferences (only preferences, exact copy of config did not work in my case) and www folder contents.

I even tried uninstall nodejs, npm, cordova and re-installing them individually and in random order only to make things worse.

macos - Cordova CLI - After update, any and all commands fail with "Er...

macos cordova command-line-interface
Rectangle 27 2

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onError);

So in your case, try this modification

function onFileSystemSuccess() {
    store = cordova.file.dataDirectory;

    //Check for the file. 
    window.resolveLocalFileSystemURL(store + fileName, appStart, downloadAsset);
}
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onError);
Uncaught ReferenceError: LocalFileSystem is not defined

Unfortunately, this didn't resolve the issue. Do you have any other idea? I can't think straight anymore. But I will check back tomorrow. Maybe, I'll have to reduce the code to just the cordova.fileand cordova.file-transfer stuff in order to find the issue.

Well, in that case, are you sure your deviceready event is triggered? I have had hard time with it not triggering for odd reasons. I was finally able to make some sense on my problems when I started using GapDebug to remote debug my app, you should try that if not already using remote debugging of built apps.

cordova - PhoneGap Build: Plugins not working (getting "undefined" err...

cordova phonegap-plugins phonegap-build
Rectangle 27 1

The problem is the config.xml syntax for whitelist. Instead of uri you should use origin:

<access uri="*" />
<access origin="*" />

I also made a typo a few days ago and missed it had <allow-navigation origin=".example.com"/> instead of <allow-navigation href=".example.com"/>

macos - Cordova CLI - After update, any and all commands fail with "Er...

macos cordova command-line-interface
Rectangle 27 0

The essence of the problem is that so long as cordova.device is undefined, your code can't be sure if that's because cordova has established that your device is not supported, or if it's because cordova is still preparing itself and deviceready will fire later (or third option: cordova didn't load properly).

The only solution is to define a waiting period, and to decide that after this period your code must assume the device is not supported. I wish cordova would set a parameter somewhere to say "We've tried finding a supported device and given up" but it seems like there is no such parameter.

Once this is established, you may want to do something specific precisely in those situations where there is no supported device. Like hiding links to the device's app market, in my case.

I've pieced together this function which should cover pretty much every situation. It lets you define a deviceready handler, a device-never-ready handler, and a waiting time.

//Deals with the possibility that the code will run on a non-phoneGap supported
//device such as desktop browsers. Gives several options including waiting a while
//for cordova to load after all.
//In:
//onceReady (function) - performed as soon as deviceready fires
//patience 
//  (int) - time to wait before establishing that cordova will never load
//  (boolean false) - don't wait: assume that deviceready will never fire
//neverReady 
//  (function) - performed once it's established deviceready will never fire
//  (boolean true) - if deviceready will never fire, run onceReady anyhow
//  (boolean false or undefined) - if deviceready will never fire, do nothing
function deviceReadyOrNot(onceReady,patience,neverReady){

    if (!window.cordova){
            console.log('Cordova was not loaded when it should have been')
            if (typeof neverReady == "function"){neverReady();}
        //If phoneGap script loaded...
        } else {
            //And device is ready by now...
            if  (cordova.device){
                callback();
            //...or it's loaded but device is not ready
            } else {
                //...we might run the callback after
                if (typeof patience == "number"){
                    //Run the callback as soon as deviceready fires
                    document.addEventListener('deviceready.patience',function(){
                        if (typeof onceReady == "function"){onceReady();}
                    })
                    //Set a timeout to disable the listener
                    window.setTimeout(function(){
                        //If patience has run out, unbind the handler
                        $(document).unbind('deviceready.patience');
                        //If desired, manually run the callback right now
                        if (typeof neverReady == 'function'){neverReady();}
                    },patience);
                //...or we might just do nothing
                } else {
                    //Don't bind a deviceready handler: assume it will never happen
                    if (typeof neverReady == 'function'){neverReady();} 
                    else if (neverReady === true){onceReady();} 
                    else {
                       //Do nothing
                    }
                }
            }
    }

}

javascript - PhoneGap: Detect if running on desktop browser - Stack Ov...

javascript cordova
Rectangle 27 0

You can't test hybrid app on browser without proper tools. Use ripple chrome extension to test your app.

Thanks but as I said this is occurring on the phone. I am remote debugging the cordova as webview in chrome to see the problem (using chrome://inspect and connecting the phone in usb debugging). Without debugging also using alert logs in the App show the same error.

android - Cordova Uncaught TypeError: Cannot set property 'require' of...

android cordova cordova-3
Rectangle 27 0

Seems that phonegap does not load the js include in the right order. I have put the include of cordova.js in the head section of my index.html and it does work now. Really strange

javascript - Phonegap/Cordova - Socket plugins end up with: undefined ...

javascript android sockets cordova
Rectangle 27 0

Figured it out. (I've never used Cordova before). Apparently you have to install a plugin in order to get access to Cordova features. Now I know!

$ cordova plugin add org.apache.cordova.device-motion

javascript - Trying to build a Chrome Cordova App, but navigator is un...

javascript android google-chrome cordova
Rectangle 27 0

Found the problem - I was loading cordova.js explicitly in my index.html. But Sencha touch was also loading cordova.js explicitly in a non-obvious way(automatically specified in app.json). Once I removed my own cordova.js inclusion it loaded fine.

javascript - TypeError: 'undefined' is not a function (evaluating 'cor...

javascript ios cordova sencha-touch
Rectangle 27 0

Had this problem too. Realized that the iOS file is named ChildBrowser.js but the Android file is childbrowser.js. Doh!

Cannot get ChildBrowser working on Cordova 2.0.0: Cannot read property...

cordova cordova-2.0.0 childbrowser
Rectangle 27 0

Problem solved. My childbrowser.js was partially downloaded which causes this error

Cannot get ChildBrowser working on Cordova 2.0.0: Cannot read property...

cordova cordova-2.0.0 childbrowser
Rectangle 27 0

I've naively overwritten the entire www folder, and this has been causing the problem.

The cordova.js file in the root of the www folder is platform specific, and I had thusly used the Android cordova.js file in my iOS project, which obviously wasn't working.

Thank you to fmertz on #phonegap for pointing me in the right direction.

RequestFileSystem undefined PhoneGap/Cordova 2.2.0 on iOS - Stack Over...

ios cordova
Rectangle 27 0

First off all, i would recommend you to check, whether you have installed npm etc. the right way. Check the tutorial over here -> CLI-Guide <-. After that you should build a total new project over your terminal. You should use these Commands to do this ->

cd ~/desktop
cordova create media media.example.com media
cd media
cordova platform add android
cordova plugin add org.apache.cordova.camera
cordova plugin add org.apache.cordova.console
cordova build

So, now open up your folder. There should be a directory like media/platforms/android/assets/www and in this directory you should find your cordova.js and cordova_plugins.js.

After you installed all like i said, and checked your $PATH Variable etc. you can try this code in your index.html to check, whether the camera-plugin is working or not:

<!DOCTYPE html>
<html>
  <head>
    <title>Capture Photo</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    var pictureSource;   // picture source
    var destinationType; // sets the format of returned value

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready",onDeviceReady,false);

    // device APIs are available
    //
    function onDeviceReady() {
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoDataSuccess(imageData) {
      // Uncomment to view the base64-encoded image data
      // console.log(imageData);

      // Get image handle
      //
      var smallImage = document.getElementById('smallImage');

      // Unhide image elements
      //
      smallImage.style.display = 'block';

      // Show the captured photo
      // The in-line CSS rules are used to resize the image
      //
      smallImage.src = "data:image/jpeg;base64," + imageData;
    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoURISuccess(imageURI) {
      // Uncomment to view the image file URI
      // console.log(imageURI);

      // Get image handle
      //
      var largeImage = document.getElementById('largeImage');

      // Unhide image elements
      //
      largeImage.style.display = 'block';

      // Show the captured photo
      // The in-line CSS rules are used to resize the image
      //
      largeImage.src = imageURI;
    }

    // A button will call this function
    //
    function capturePhoto() {
      // Take picture using device camera and retrieve image as base64-encoded string
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: destinationType.DATA_URL });
    }

    // A button will call this function
    //
    function capturePhotoEdit() {
      // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
        destinationType: destinationType.DATA_URL });
    }

    // A button will call this function
    //
    function getPhoto(source) {
      // Retrieve image file location from specified source
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: source });
    }

    // Called if something bad happens.
    //
    function onFail(message) {
      alert('Failed because: ' + message);
    }

    </script>
  </head>
  <body>
    <button onclick="capturePhoto();">Capture Photo</button> <br>
    <button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
    <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
    <button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
    <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
    <img style="display:none;" id="largeImage" src="" />
  </body>
</html>

So...maybe you try to test my suggestions for you now and give me a feedback, if it worked, or where i can help you more :-)!

Edit for the Answer from Nick -> Standard Cordova index.html code:

<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=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, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <meta name="msapplication-tap-highlight" content="no" />
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();
        </script>
    </body>
</html>

I appreciate the response and the explanation. Also, I'm using the capture plugin instead of the camera plugin so I can capture video too. Based on what I've read though, I will probably mix and match where I'll use the camera plugin for capturing pictures and the capture plugin for capturing video.

cordova - PhoneGap: Capture plugin with navigator.device undefined - S...

cordova phonegap-plugins cordova-plugins
Rectangle 27 0

<!DOCTYPE HTML>
<html>
  <head>
      <script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
      <script type="text/javascript" charset="utf-8">

    var deviceInfo = function(){
      alert(navigator.network.connection.type);
    }

    function init(){
        console.log("GOT AN ONLOAD!!!")
        document.addEventListener("deviceready", deviceInfo, true);
    }
  </script>
  </head>
  <body onload="init();">
      A body...
  </body>
</html>

Also, when you moved from iOS to Android did you use the Android version of cordova.js? There is a platform dependent cordova.js for each platform.

@Simon MacDonald , hii i have given the same code as above but not able to get, i'm using cordova-2.0.0.jar file, please help me

android - Phonegap/Cordova - TypeError: Result of expression 'navigato...

android cordova
Rectangle 27 0

your plugin was my first choice in cordova 2.6 window.storekit is (undefined) doesn't intialized and i tried many things to fix but in vain. so, i have upgraded to cordova 3.0 and now it works with your plugin. But thnx for your reply

javascript - Ios In-app Purchase RequestData Function not firing? - St...

javascript ios cordova in-app-purchase
Rectangle 27 0

Okay, here are a few things that are probably tripping you up. First if the config.xml file exists in res/xml then it will take precedence over plugins.xml. So you will need to add your plugin line to config.xml instead.

Make sure you are including the .js file for your Toast plugin.

Third, window.plugins has been deprecated away so you may need to modify the .js if you are using PhoneGap 2.0.0 or better. Check out my blog post on the topic. The root change is that you now need to new PluginName in your JS as it is no longer put in window.plugins by default.

Simon, you just saved me. I spent the past 5 hours staring at my code trying to understand what's happening. I was putting the plugin in "plugins.xml" but not in "config.xml"! Thanks a lot.

@Simon MacDonald i am stuck and always getting an error: Uncaught TypeError: Cannot read property 'applicationPreferences'. Please help me.

cordova - Phonegap plugin for android is not working. Why? - Stack Ove...

android cordova plugins undefined
Rectangle 27 0

JosephT is right. Also my device plugin was wrongly installed. "cordova run android" fixes it.

What I did: new project with cordova add plugins with cordova add platform with cordova open project in Eclipse, start make the deployment to device by Eclipse One plugin (not from cordova) was working, but still I got "device is not defined, when I listed my plugins in CLI, device was installed, but somehow not working.

When used in CLI "cordova run android", probably Android platform part of project was re-created by CLI better than by Eclipse and device plugin start working.

Attention! When you will run "cordova run android" from CLI, code which you created in Eclipse will be overwritten by default from www folder in top of project. Make backup of project and try it, you will see what happen.

cordova - PhoneGap 3.x/Windows Phone 8 - all plugins are undefined - S...

cordova windows-phone-8 phonegap-plugins