Dave Chen
Dave Chen

Reputation: 10975

DeviceReady not firing on PhoneGap Build (Bd)

My config.xml is as follows:

<?xml version="1.0" encoding="UTF-8" ?>
    <widget xmlns = "http://www.w3.org/ns/widgets"
    xmlns:gap     = "http://phonegap.com/ns/1.0"
    id            = "com.example.test"
    versionCode   = "10" 
    version       = "1.0.0">

    <gap:plugin name="org.apache.cordova.device" />
    <gap:plugin name="org.apache.cordova.network-information" />
</widget>

I reference both the device, and network information, however, with my JavaScript (wrapped within within head in index.html):

<script src='phonegap.js'></script>
<script>
    alert("Loaded.");
    document.addEventListener("deviceready", function() {
        alert("Fired.");
        alert(device.uuid);
    });
</script>

I get a popup Loaded. as expected, but I don't get Fired. or the device's UUID either.

I have tried adding separately the phonegap/cordova libraries respectively (one at a time):

<script src='phonegap.js'></script>
<script src='cordova.js'></script>

They cause the application to show Error initializing Cordova: Class not found".

Snap of plugins loaded into the online build:

I'm running Android 4.0.3. I've also tried accessing device but it just says device in undefined. I have disabled hydration as well. What should I try next? (I'd like to get device.* and deviceready event to work)

Upvotes: 1

Views: 3855

Answers (1)

byJeevan
byJeevan

Reputation: 3838

This should work for you :

<script>
document.addEventListener("deviceready", OnDeviceReady, false);

function OnDeviceReady()    {
alert("Device is ready");
}
</script>

Also refer this link

Upvotes: 3

Related Questions