PhoneGap: How to pass parameters to the index.html from the Activity class

4,727 views
Skip to first unread message

karan

unread,
Jun 19, 2012, 8:33:19 AM6/19/12
to phon...@googlegroups.com
Hello,

I am developing on Android OS.
My activity class loads the index.html as below:
super.loadUrl("file:///android_asset/www/index.html");

1) I needed to send some parameters to the index.html
2) Then read these parameters in the index.html via javascript.

Please help.
Thanks
karan

anurag gautam

unread,
Jun 19, 2012, 8:37:06 AM6/19/12
to phon...@googlegroups.com
i think You have to put a Boolen value which  while your application is start, when on ready function you can paost that value,



karan

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



--
Thanks!
With regards
ANURAG GAUTAM
7814155605
Linkedin profile


Jas karan

unread,
Jun 19, 2012, 9:43:37 AM6/19/12
to phon...@googlegroups.com, anuragg...@gmail.com
Hi Anurag,

Thanks alot for replying....
can you please show me an example or documentation...
I need to set some data in the index.html from the activity java class.

thanks alot
karan

Philzen

unread,
Jun 19, 2012, 10:37:26 AM6/19/12
to phon...@googlegroups.com, anuragg...@gmail.com
Hi Karan,

it's dead simple once you see it (because we all have seen it before)... you go

super.loadUrl("javascript: { var myVariable = "I can push any javascript from Android Container to the DOM!"; document.body.innerHTML += myVariable; }");

after you loaded whatever html page you like.The above line is written straight from the head so test yourself, but if you want to see it working in a class you can take a look at the two files found here: https://github.com/Philzen/WebView-MultiTouch-Polyfill/tree/master/src/com/changeit/wmpolyfill

MainActivity basically is the same as yours, WebClient-Class hooks in, can intercept user actions at any time and/or inject javascript code into the webview.

Hope this helps.

Cheers - Phil


Am Dienstag, 19. Juni 2012 15:43:37 UTC+2 schrieb karan:
Hi Anurag,

Thanks alot for replying....
can you please show me an example or documentation...
I need to set some data in the index.html from the activity java class.

thanks alot
karan

On 19 June 2012 18:07, anurag gautam <anuragg...@gmail.com> wrote:
i think You have to put a Boolen value which  while your application is start, when on ready function you can paost that value,

On Tue, Jun 19, 2012 at 6:03 PM, karan <jaskar...@gmail.com> wrote:
Hello,

I am developing on Android OS.
My activity class loads the index.html as below:
super.loadUrl("file:///android_asset/www/index.html");

1) I needed to send some parameters to the index.html
2) Then read these parameters in the index.html via javascript.

Please help.
Thanks
karan

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

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



--
Thanks!
With regards
ANURAG GAUTAM
7814155605
Linkedin profile


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

Sandeep Singh

unread,
Jun 19, 2012, 10:47:50 AM6/19/12
to phon...@googlegroups.com
You can use html5 localStorage or sessionStorage to do that as well.
In your activity class initialize a javascript session variable like this
this.sendJavascript("sessionStorage.setItem('varName','varValue')");

and you can use this after your index.html has loaded.

Sandeep

Jas karan

unread,
Jun 19, 2012, 12:52:15 PM6/19/12
to phon...@googlegroups.com
Thanks alot Sandeep!
I will try this approach. 

Thanks alot
karan    

Jas karan

unread,
Jun 19, 2012, 12:55:10 PM6/19/12
to phon...@googlegroups.com, auste...@klimagipfel.de
Thanks alot Phil !
This is great, appreciate the help.

Thanks alot
karan   

Jas karan

unread,
Jun 19, 2012, 1:07:18 PM6/19/12
to phon...@googlegroups.com, auste...@klimagipfel.de
I have another similar issue. Once the html is loaded and working; is there a way to call a javascript function of the loaded html from the activity class. 
Basically i have a mixed UI, half is native controls and half is phonegap html. On a native button click an event is sent back to the activity class, then in this event handler i need to send a parameter to the already loaded html view and then call its javascript function.
Its like this:
Step1: Activity class loads native controls and phonegap-html
Step2: User clicks on native control button, an event is fired
Step3: The activity class has the event handler for the button. 
Step4: In this activity-class event handler some new parameter has to be passed to the already loaded phonegap html.
Step5: Then the activity-class event handler has to call a javascript function inside the loaded phonegap html.

Please help.

Thanks alot
karan   

On 19 June 2012 20:07, Philzen <auste...@klimagipfel.de> wrote:

Santhosh san

unread,
Feb 20, 2015, 7:21:52 AM2/20/15
to phon...@googlegroups.com, jaskar...@gmail.com
hello sir, 
      Am new of the android i don't know pass data from phonegap to android main activity class any tel me pl..
       advance thank you..

Shyaam Jadhav

unread,
Feb 26, 2015, 2:42:33 AM2/26/15
to phon...@googlegroups.com, anuragg...@gmail.com, auste...@klimagipfel.de
hi Phil if to send data from android to javascript is this,


super.loadUrl("javascript: { var myVariable = "I can push any javascript from Android Container to the DOM!"; document.body.innerHTML += myVariable; }");

what If I want the vice versa sending data from javascript to android?

Regards,
Shyaam. 
Reply all
Reply to author
Forward
0 new messages