Pass a value to loadURL - Android

前端 未结 3 713
灰色年华
灰色年华 2020-12-30 08:32

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=\"         


        
相关标签:
3条回答
  • 2020-12-30 09:16

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

    0 讨论(0)
  • 2020-12-30 09:24

    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);
    
    0 讨论(0)
  • 2020-12-30 09:33

    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.

    0 讨论(0)
提交回复
热议问题