document.addeventlistener( deviceready ondeviceready false) not working in Blackberry

4,524 views
Skip to first unread message

Nasir

unread,
Mar 9, 2012, 2:17:01 AM3/9/12
to phon...@googlegroups.com
Hi all,

I am using phonegap 1.4.1 and it is working perfectly on Android.

But Same code doesnt work on Blackberry.document.addeventlistener is not firing in it.
I have tested it on Blackberry 9800(OS 6).

Why it is not working?

Drew Walters

unread,
Mar 9, 2012, 10:32:54 AM3/9/12
to phon...@googlegroups.com
Please provide some sample code exhibiting the issue.

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

Nasir

unread,
Mar 12, 2012, 1:12:26 AM3/12/12
to phon...@googlegroups.com
Here is the code.The listener is not working it seems so because alert is not shown.It works on android.But on blackberry it doesnt.

<script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
<script type="text/javascript" src="jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="flot/jquery.flot.min.js"></script>
<script type="text/javascript" src="flot/jquery.flot.stack.min.js"></script>
<script type="text/javascript" src="flot/jquery.flot.pie.min.js"></script>
<link rel="stylesheet" href="jquery.mobile-1.0.1.min.css" />
<script type="text/javascript" src="jquery.mobile-1.0.1.min.js"></script>
<link rel="stylesheet" href="jquery.mobile.tabs.css" />
<script type="text/javascript" src="jquery.mobile.tabs.js"></script>
<script type="text/javascript">
function onDeviceReady() {
alert("Hi");
}
document.addEventListener('deviceready', onDeviceReady, false);
</script>


Drew Walters

unread,
Mar 12, 2012, 8:58:22 AM3/12/12
to phon...@googlegroups.com
Couple of things to try:

1. Make sure you are using the BlackBerry version of phonegap.js.
Each platform has a specific javascript file.
2. The recommended way to add a listener for deviceready is the following:


<script type="text/javascript" charset="utf-8">

function onload() {
// Wait for PhoneGap to load


document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
// do stuff
}
</script>
<body onload="onload()">
3. If #1 or #2 do not help, try removing the other script inclusions.
Maybe one of them is conflicting with phonegap.

nobby_...@yahoo.com

unread,
Mar 21, 2012, 9:01:27 AM3/21/12
to phonegap
Hi,

Did you ever find a solution to this issue? I have exactly the same
thing which, as with yours, works fine on all other devices but not
Blackberry. Interestingly, it works for Blackberry on an old version
of Phonegap (0.9.5) but not 1.4.1.

Regards

Dan
Message has been deleted

Nasir

unread,
Mar 21, 2012, 12:40:55 PM3/21/12
to phon...@googlegroups.com

Custom events are not supported in the RIM BrowserField (web browser view), so the deviceready event will never fire.

A workaround is to manually query PhoneGap.available until PhoneGap has fully loaded.

function onLoad() {
   
// BlackBerry OS 4 browser does not support events.
   
// So, manually wait until PhoneGap is available.
   
//
   
var intervalID = window.setInterval(
     
function() {
         
if (PhoneGap.available) {
              window
.clearInterval(intervalID);
              onDeviceReady
();
         
}
     
},
     
500
   
);
}

function onDeviceReady() {
   
// Now safe to use the PhoneGap API
}

nobby_...@yahoo.com

unread,
Mar 21, 2012, 12:44:38 PM3/21/12
to phon...@googlegroups.com
Thanks for your reply. Does this also apply to OS6?

Regards

Dan

Drew Walters

unread,
Mar 21, 2012, 12:48:46 PM3/21/12
to phon...@googlegroups.com
Nasir,

Now I am completely confused. Originally you referenced OS 6. Your
most recent reply references OS 4. OS 4 is no longer being actively
supported by PhoneGap and PhoneGap 1.4.1 certainly will not work on OS
4. 'deviceready' does in fact fire on OS 5, 6, 7 devices.

nobby_...@yahoo.com

unread,
Mar 21, 2012, 12:50:32 PM3/21/12
to phon...@googlegroups.com
OK scrap that, I found it. After spending most of the day trawling the internet wondering why the event wasn't firing, I started delving into the Phonegap code and adding alert() debug lines and found that onDeviceReady wasn't firing because _nativeReady was never being set. Knowing that it was having trouble loading the native stuff helped and it turns out I was missing the plugins.xml in my blackberry project. If anyone encounters this problem, it is because if you upgrade from an older version of phone gap (<1 I think), you need a plugins.xml file adding to your project which looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
<plugins>
<plugin name="App" value="com.phonegap.app.App"/>
<plugin name="Device" value="com.phonegap.device.Device"/>
<plugin name="Camera" value="com.phonegap.camera.Camera"/>
<plugin name="Network Status" value="com.phonegap.network.Network"/>
<plugin name="Notification" value="com.phonegap.notification.Notification"/>
<plugin name="Accelerometer" value="com.phonegap.accelerometer.Accelerometer"/>
<plugin name="Geolocation" value="com.phonegap.geolocation.Geolocation"/>
<plugin name="File" value="com.phonegap.file.FileManager"/>
<plugin name="FileTransfer" value="com.phonegap.http.FileTransfer"/>
<plugin name="Contact" value="com.phonegap.pim.Contact"/>
<plugin name="MediaCapture" value="com.phonegap.media.MediaCapture"/>
<plugin name="Battery" value="com.phonegap.battery.Battery"/>
</plugins>

tbald

unread,
Oct 22, 2012, 7:32:24 PM10/22/12
to phon...@googlegroups.com
Can you give more information?  I have a similar plugin.xml to the one you have below, except for I have "org.apache.cordova" instead of "com.phonegap", which should be the same thing.  But my blackberry does not look like it is firing the onDeviceReady event.  iOS does, for the same code, so I don't think it is the code, I think it is something with the device.

Also, where did you "add alerts"?  To what code, precisely?  Was it to the cordova-2.0.0.js script, per chance?

tbald

unread,
Oct 22, 2012, 8:08:14 PM10/22/12
to phon...@googlegroups.com
Never mind.  Problem was that I was referencing the wrong cordova version in my index.html.  The joys of copying between two different machines.  Thanks.


On Wednesday, March 21, 2012 12:50:32 PM UTC-4, nobby_...@yahoo.com wrote:
Reply all
Reply to author
Forward
0 new messages