Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Trusted Contributor
lathajagan
Posts: 118
Registered: ‎03-06-2013
My Device: Blackberry Z10
Accepted Solution

ondeviceready not firing in bb10 phonegap application

Hello ,

i am trying to develop a HTML5,JQuery based application with corodova(phonegap), but many times i observe that app plays video(which is my fist section in html5) and then app doesnt change to next section, i guess this might be becuase of ondeviceready not firing as i see logs on my debugger like this.

ondeviceready not fired for more than 5secs.

 

Please let me know, how this can be solved.this happens atleast 4/10 times.

--------
- If a post contains the solution to the problem, please click "Accept as Solution"
- If a post contains helpful content, please give it a "Thumbs Up"

developer.blackberry.com
@BlackBerryDev
BlackBerry Development Advisor
bryanhiggins
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3

Re: ondeviceready not firing in bb10 phonegap application

Hi,

 

Which version of PhoneGap are you using?

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C

Re: ondeviceready not firing in bb10 phonegap application

I develop for both - and can use the same code on both platforms - tricky but you can do it

For straight PG you need something  like this...

<head>

function onLoad() {
            document.addEventListener("deviceready", start, false);
            app.initialize();
    }
 </head>

<body onload="onLoad">
</body>

It is REALLY important that that code is AFTER you load PhoneGap/Cordova and in the HEAD of the INDEX page

There are other issues with PG right now as well (badly designed)

There's an initialization script that actually starts Cordova up

It's broken...

I include both cordova and this (I call it cordovastart)

/*
 * 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.
 */
var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicity call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

 This is a very small modification and makes everything work

 

 




Click the like button if you find my posts useful!
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10

Re: ondeviceready not firing in bb10 phonegap application

@lathajagan: Did the response above answer your question? If so, can you please accept the response as the solution? If not, please let us know.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Trusted Contributor
lathajagan
Posts: 118
Registered: ‎03-06-2013
My Device: Blackberry Z10

Re: ondeviceready not firing in bb10 phonegap application

hello peardox ,
thanks for the suggestion.
i have tried your cordovastart.js in bb7.1 OS, device ready event never fires, can u please help me why this is the problem? i am now developing a simple BB7.1 where i need to login to a link after my device ready event and use the cordova history api for retaining the history when user presses back button for which i am registering the back button event in cordova.
can u please help me with this?
--------
- If a post contains the solution to the problem, please click "Accept as Solution"
- If a post contains helpful content, please give it a "Thumbs Up"

developer.blackberry.com
@BlackBerryDev
Developer
kamal_nigam
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10

Re: ondeviceready not firing in bb10 phonegap application

Hi Latha we have some issue is BB7.1 and below. but that does not mean you are not able to execute onDevice.

please check your JS location and other html code it will execute. if u are not able to do than i can share sample code with u

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Trusted Contributor
lathajagan
Posts: 118
Registered: ‎03-06-2013
My Device: Blackberry Z10

Re: ondeviceready not firing in bb10 phonegap application

hello all,
this issue is solved now.
issue was because in our application i was first playing a video via html5 video tag then going to index.html, which is stopping because of the 'onstalled' error which is common, so i have solved it by doing successcallback which i do the same for 'onended' event of video.
here there was no cordova issue at all, it was happening sometimes true, but its as rare as 1 out of 50 times.
--------
- If a post contains the solution to the problem, please click "Accept as Solution"
- If a post contains helpful content, please give it a "Thumbs Up"

developer.blackberry.com
@BlackBerryDev