JavaScript Events not working with Android/PhoneGap Build/XCode.
I am using PhoneGap 0.9.4 to write an application (using XCode on Mac OS X 10.6) and using the PhoneGap Build to build the binaries. Try as I may, the Android JavaScript events do not work. I have tried signing the APK file but no joy. I can confirm (80% sure) that it's likely to be the PhoneGap Build service at fault here: I copy the sample Android application from the SDK and set it up in Eclipse and run it to my Samsung Galaxy S through USB and the events work properly.
-
Currently we're using an older build of PhoneGap on PhoneGap Build (PhoneGap 0.9.2). We're going to bump it up to 0.9.4 soon.
-
-
Have this same thing occurring. I can use Eclipse and build it and the Events work. But take the same exact files and input using PhoneGap Build, the Events (or phonegap functions) don't work.
They don't even load when calling:
document.addEventListener("deviceready", onDeviceReady, false);
It just doesn't load.
If bypassing this in the body onLoad(), all my scripts work fine.
I use 0.9.4 in my Eclipse app.
Alternative question:
I have been enclosing a phonegap.* file with my zip, should I not be doing that? Either way, it does not work, but when I omit it, I get an error from the phone saying it could not find server file://www/index.html-
I'm having this exact problem--it makes running unobtrusive JS pretty much impossible on Android. Mike, your solution is just to put everything in body.onLoad?
-
-
-
-
-
-
I overlooked this for a while, sorry Mike.
Don't include phonegap.js, with any version, in the app you upload to PhoneGap Build. Each different PhoneGap platform requires a different build of phonegap.js. In addition, each platform's build of phonegap.js is tied to the current version of the native code it was built with.
So if you upload, say, phonegap-0.9.4.js for Android, it will not work at all on any other platform. And if we're not running 0.9.4 on our Android server (right now we're on 0.9.5.1, moving to 0.9.6 soon), it may not work on Android either.
To work around this, we ask you to put a (script src="phonegap.js") tag in your index.html to load the current version we have on the server, for your platform. The deviceready event should fire correctly after that. -
-
I am experiencing this same issue, where the deviceready event is not being triggered on my droidx, it works fine in the iphone build. The application ID is 13511. I tried a test with just
script source to "phonegap.js"
and the following
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("device ready");
}
Pretty much copy and paste from the documentation but put in the alert instead of the other listeners, and it did not work.
I am not including a local phonegap.js file. -
-
Hey James,
A while ago I wrote a simple test (https://github.com/hardeep/PhoneGap-B...) however make sure to checkout the branch named correct
I just tested it out and the android simulator fired fired my deviceready handler.
Hardeep Shoker -
-
Sorry, I should have been more specific in my previous post. Yes the deviceready event gets triggered in the simulator. I'm using Ripple, it does not however get fired on the actual device, hence it does not work on my droidx. Today, I installed eclipse and went through the hello world doc and added in the deviceready. It does work when I build it locally and run on my droid, but it does not work when I send the same app through build.phonegap.
-
-
Hey James,
I do not have a droidx, or as a matter of fact have one in the office to test, however I was able to get it to run on a Nexus S. If you could verify by running that application I provided above.
However please remember to package the branch correct
Hardeep Shoker -
-
Hey Hardeep,
I tested out your debug app and it worked correctly on the device! I noticed that you did not include a config.xml and when I built the app it it had all of the features and permissions turned on. After a couple more builds with some guess and check, I was able to determine that the config.xml must include the line for
feature name="http://api.phonegap.com/1.0/network"
or the deviceready event will not get fired on the android build, the ios build works fine without this line.
- James -
-
Hey James,
Great that you were able to get it working! I will note this down and look into once I have a bit of time. The reason why is because all the features are provided in IOS be default where as Android's must be specified.
On a side note network enables access network state.
Hardeep Shoker -
-
-
-
hi
please help me in this code..
package com.heloo.namespace;
import android.app.Activity;
import android.os.Bundle;
import com.phonegap.*;
public class HelooActivity extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
this will give me a error .
thanks! -
-
Hi, i am having the same problem... ondeviceready is not trigger on device... everything is working fine in the simulator but on real device some times the ondeviceready is not triggered. i am running on android simulator. i have tried every solution given above like putting config.xml with index.htnl file also fire onload event on body tag but still not working on real device... please help me...
-
-
@thankisk: Without knowing what code you're running, it's hard to know what's failing.
Try putting this in a script tag in your index.html file:
document.addEventListener("deviceready", function () {
alert('device ready')
}, false)
Does the alert come up? -
-
-
I've got the same problem and the last post didn't work. On the iOs simulator is working ok but on a real device is not calling the "onDeviceReady" event.
What I realized is that I can use the "onLoad()" event but for example "device.uuid" is not working.... so It looks that some part of PhoneGap framework is not loading. I can't see where the problem is so please, I need you help because I'm stack and I am not able to send the app.
Thank you very much to everyone and to the PhoneGap team for their fantastic work. -
-
Hi,
Same problem for me.
I am using samsung galaxy 2 s - android.
Another weird thing is javascript loads only if inline in index.html.
When in other html documents a declared javascript function will be found only if as I wrote inline in index.html ! -
-
Hi Andrew,
My code is like below
function init() {
document.addEventListener("deviceready", function() {
alert("Device Ready...");
}, true);
}
and i have call init() on body load....
but the device ready is not called. I am using cordova 1.5.0 with android device.
what could be the reason?
Please Help...
Thanks
Shail. -
-
I have the same problem - no matter what I do I can't get the "deviceready" event to show up. I even went and grabbed the phonegap start example and it just stays on "Connecting to device" because onDeviceLoad() is never called
-
Loading Profile...


Twitter,
Facebook, or email.




EMPLOYEE


