Connection API issue in 1.1.0 for Android

25 views
Skip to first unread message

ericburnley

unread,
Oct 6, 2011, 12:36:07 PM10/6/11
to phonegap
I know the Connection API has had some work done in 1.1.0 for Android,
and it's definitely working better. But I'm still having an issue
with it running right away upon page load. I've used the example code
from the Connection API page (checkConnection()).

I'm seeing different behavior between the emulator (2.3.3) and my
phone (Droid Incredible, 2.3.4):

Emulator behavior: Page loads, checkConnection() is fired, returns
Cell 3G. Things work.

Phone behavior: Page starts loading, PG/DOM loads, hits
checkConnection() function and chokes on the following line: var
networkState = navigator.network.connection.type; If I hit my
refresh button (my own button, which calls the same Load function with
the checkConnection function in it first), it runs through the
navigator.network.connection.type line and I get an alert that is
placed inside that function, but the networkState returned is
undefined. If I hit the back button (this is a multi-page app), and
then come back in and refresh, things work fine and I receive the Cell
3G connection.

I'm using deviceready to trigger the initial Load function call, which
calls the checkConnection function. I've switched some things around
recently to try and get the connection checking in place, so I realize
I may just have a stupid mistake someplace, but I *think* I've gone
over this enough to have ruled that out.

Just wondering if anyone's seen anything related to Connection API on
Android 2.3.4 or if there are any ideas.

ericburnley

unread,
Oct 6, 2011, 1:36:46 PM10/6/11
to phonegap
Hmmmmkay, so maybe I posted too quickly.

Evidently something related to PG loading is happening on any page,
whether I'm specifically calling the Connection API or not. For
instance, if I go to a page that does not use the checkConnection
function, I still see the page spin. If I either refresh or hit the
back button and visit the page again, everything loads fine. Then I
can subsequently go to other pages and see things load fine (including
the checkConnection() function). It seems like the deviceready is not
firing.

Could I have something loading out of order? I put phonegap.js at the
top, in the head so it'd load right away, and it does (i put an alert
in phonegap.js to make sure).

ericburnley

unread,
Oct 11, 2011, 4:55:20 PM10/11/11
to phonegap
To close this out, after some digging it looks like my issue was this:

http://groups.google.com/group/phonegap/browse_thread/thread/b1f0f4aa5473d2de/306044d42be7c8a0?lnk=gst&q=android+deviceready#306044d42be7c8a0

Bryce's suggestion of swapping window.location with
navigator.app.loadUrl("file:///android_asset/www/mypage.html") worked.
Reply all
Reply to author
Forward
0 new messages