Naveen
Naveen

Reputation: 1060

Pass a value to loadURL - Android

Is it possible to pass a value to the URL mentioned in webView.loadUrl? something like this??

webView.loadUrl("file:///android_asset/www/index.html#value="+value);

or is there any way to pass a Java String value to the Javascript function in loadURL?

Upvotes: 11

Views: 14925

Answers (3)

user2416093
user2416093

Reputation: 47

I found a simple solution. Below is the code which is working

String s = "http://10.0.2.2/myhtml/add.php?bc=" + bc;   
myWebView.loadUrl(s);

Upvotes: 0

Naveen
Naveen

Reputation: 1060

I found the solution.. posting it here for the sake of others :)

I added the following snippet of code in my Activity class which solved the problem,

webView.setWebViewClient(new WebViewClient() {  
                @Override  
                public void onPageFinished(WebView view, String url)  
                {  
                    webView.loadUrl("javascript:callMe(\""+data_val+"\")");

                }  
            });  

Thanks all :)

Upvotes: 13

Lukas Knuth
Lukas Knuth

Reputation: 25755

You'll want to use a GET-Query string to do so. Note that the maximum length of a URL is 256 chars!

After you supplied your arguments that way, you can use JavaScript to read them (by cutting them out of the URL). Here is a Code-Snipped and an article on this topic.

Upvotes: 0

Related Questions