[PhoneGap] Android - Issue with deviceready and window.location

Showing 1-16 of 16 messages
[PhoneGap] Android - Issue with deviceready and window.location Jacob 9/29/11 10:21 PM
I've discovered an issue with working between two HTML files in
Phonegap on Android and the deviceready event.

1) I have an index.html page that triggers deviceready fine
2) I have another page that is simply a demo page from the Phonegap
wiki docs.

When I redirect to a page within Javascript based on a server response
from Facebook, I use window.location.href="pagename.html". The page
loads fine, but deviceready is not triggered. However, if I move this
same page to be the first page loaded by Phonegap, it triggers
deviceready fine.

I ran a test to see if it was an isolated issue with
window.location.href by placing a simple link on the homepage, and
when I loaded the second page through that link, deviceready triggered
fine. It seems that if I want to navigate to sub-pages, I can only do
so through href links and not via javascript? I saw Simon's example of
<a href="#" onclick="window.location='home.html'>link</a>, but that is
a different scenario since the user isn't clicking a link for this to
happen. It happens from a JSON request result.

Appreciate any tips/ideas before I end up re-writing and hacking this
together incorrectly just to get deviceready to work.

Cheers,
Jacob
Re: Android - Issue with deviceready and window.location bass 9/30/11 12:49 AM
If the deviceready event already has triggered, you can test with
if(device){}.
Re: Android - Issue with deviceready and window.location Jacob 9/30/11 11:16 AM
It's definitely not triggering on second page ever if the page is
loaded via window.location within JS. 'device' is never constructed.

Uncaught ReferenceError: device is not defined at file:///android_asset/www/main.html:11
Re: Android - Issue with deviceready and window.location Bryce Curtis 9/30/11 12:28 PM
PhoneGap gets notified whenever a new page is to be loaded.  However, there appears to be a bug in Android that prevents this from happening when window.location is set.  As a result, the new page is loaded in place of the existing page and PhoneGap doesn't have any way to intercept the request.  

As a solution, instead of using window.location, use

navigator.app.loadUrl("file:///android_asset/www/home.html");

Note that you have to include the entire URL, not just relative part.
Re: Android - Issue with deviceready and window.location Bryce Curtis 9/30/11 12:59 PM
The Android bug for this is http://code.google.com/p/android/issues/detail?id=9122

Star it if you want to cast your vote for getting it fixed.
Re: Android - Issue with deviceready and window.location Jacob 9/30/11 1:09 PM
You're a genius... this fixed it. Thanks Bryce!
Re: Android - Issue with deviceready and window.location Yulya 10/3/11 12:37 AM
It doesn't work for me,
please look at the test project, cannot find an error by myself
(android build target 2.2, phonegap 1.0.0, jquery 1.6.2)

project www folder: http://dl.dropbox.com/u/20618915/Phonegap%20Reload%20Test/www.rar
Re: [PhoneGap] Re: Android - Issue with deviceready and window.location WordWarrior 10/3/11 1:09 AM
i think u need to include the phonegap.js file everywhere you use the phonegap API's


--
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

Re: Android - Issue with deviceready and window.location Yulya 10/3/11 11:43 PM
Solved
Manifest file caused the problem, if somebody faces the same, my
problem was with upgrading an app to phonegap 1.0.0, see
http://simonmacdonald.blogspot.com/2011/07/upgrading-your-phonegap-android.html
If manifest file contains only one activity, nothing happens after
logcat's:
...
App.loadUrl('file:///android_asset/www/home.html',null)
Starting activity: Intent, ...
...

Thanks everyone.

On Oct 3, 1:09 pm, Nimish Nayak <wordwarrio...@gmail.com> wrote:
> i think u need to include the phonegap.js file everywhere you use the
> phonegap API's
>
>
>
>
>
>
>
Re: Android - Issue with deviceready and window.location Pacer31 10/19/11 10:23 AM
I've recently ran into this same problem.  Like you said the..using..navigator.app.loadUrl("file:///android_asset/www/login.html");

Appears to solve the deviceready issue.  But I'm running into a problem when using an emulator in Eclipse; sometimes I get the following here when it attempts to perform this function and at other times it works just fine?

An alert box pops up with the following information:
"The connection to the server was unsuccessful. (file:///android_asset/www/login.html")

Using Phonegap1.1.0, compiled with Android 3.2; 2.3 emulator.

Is it just an emulator issue or is my url not written correctly?
Re: Android - Issue with deviceready and window.location Jurgen B. 11/15/11 6:39 AM
@ Bryce, thank you for this piece of code. I have wasted a lot of time
on this... too bad it took me so long to find this answer.

@ Pacer, you were missing a double quote in front of file? But I hope
by now, you have figured that out already :)
Re: Android - Issue with deviceready and window.location Paul Beusterien 12/26/11 8:53 AM
When I updated from PhoneGap 1.1.0 to 1.3.0, navigator.app.loadUrl stopped working to allow the loaded page to execute PhoneGap capabilities.

Any suggestions on how to get PhoneGap capabilities back?

Thanks,
Paul
Re: Android - Issue with deviceready and window.location Paul Beusterien 12/26/11 11:27 AM
Found the solution. Android now needs a whitelist file.  This res/xml/phonegap.xml file keeps navigator.app.loadUrl working:

<?xml version="1.0" encoding="utf-8"?>

<phonegap>

    <access origin="http://127.0.0.1*"/>

    <access origin="http://192.168.0.104*"/>

    <log level="DEBUG"/>

</phonegap>


where 192.168.0.104 is the base of the url I'm passing to loadUrl. 


Re: Android - Issue with deviceready and window.location Rob Schmuecker 4/13/12 9:35 AM
Hi Paul et al,

First of all, cracking work with Weinre and a big thanks to all who contribute - it's a formidable tool very valued by the community it serves.
I am adding this here as I am sure it has something to do with this topic.  I am trying to setup a dev enviroment following the tutorial at sencha http://www.sencha.com/learn/a-sencha-touch-mvc-application-with-phonegap/ which works absolutely fine on my Android emulator running Gingerbread 2.3.3 aswell as on a device with same operating system.  I am doing this on windows via Eclipse and have taken a headstart of that from the phonegap intro to Android However when I add in the script tag to connect to weinre it breaks the javascript for some reaons citing that the "device is not defined" after this being in the index.html with all relevant sencha files declared before this point.

<script type="text/javascript">
            document.addEventListener("deviceready", app.mainLaunch, false);
</script>       
<script src="http://10.0.0.104/target/target-script-min.js#anonymous"></script>

where 10.0.0.104 is the address of my dev machine.

This in turn calls the app.mainLaunch method which kicks up the error.

The method being called is as follows

mainLaunch: function() {
        if (!device || !this.launched) {return;}
        this.views.viewport = new this.views.Viewport();
    }

and the line where the error occurs is

if (!device || !this.launched) {return;}

As mentioned this only occurs when including weinre, without it the application deploys and runs as it ought to.  I notice that weinre does infact receive the connection when viewing the client of weinre which I have running on port 80.

I have also followed your above tip of adding the res/xml/phonegap.xml file with appropriate origin, in this case :-

<?xml version="1.0" encoding="utf-8"?>
<phonegap>
<access origin="http://127.0.0.1*"/>
<access origin="http://10.0.0.104*"/>

<log level="DEBUG"/>
</phonegap>


However I am still unable to launch the application due to the error (which I can see in the debug console of Eclipse the output of which I include below):-

04-13 18:16:28.259: E/Web Console(21504): Uncaught ReferenceError: device is not defined at file:///android_asset/www/app/app.js:8

I would very much appreciate some insight as to why this might be occuring and feel that this was the most appropriate place to ask.

Thanks kindly in advance for your efforts.

Rob.
Re: Android - Issue with deviceready and window.location Patrick Mueller 4/18/12 5:34 AM
On Friday, April 13, 2012 12:35:25 PM UTC-4, rob1308 wrote:
I am adding this here as I am sure it has something to do with this topic.  

I've created a thread on the weinre google group for this:


Let's move the discussion there.
Re: Android - Issue with deviceready and window.location prathiksha gowda 9/25/12 5:43 AM
Thanks Bryce it worked wonders for me!!