简体   繁体   中英

Android how to pass url in android iframe webview?

Android how to pass url in android iframe webview ? I'm trying to pass url dynamically form server so what i do

if(ResponseProduct.video!=null) {

                            String html = "<iframe width=\"450\" height=\"260\" src=\""+ResponseProduct.video+"\" ></iframe>";
                            WebView webView = (WebView) view.findViewById(R.id.video);
                            webView.setVisibility(View.VISIBLE);
                            webView.getSettings().setPluginState(WebSettings.PluginState.ON);
                            webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
                            webView.getSettings().setJavaScriptEnabled(true);
                            webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
                            webView.getSettings().setSupportMultipleWindows(true);
                            webView.setWebChromeClient(new WebChromeClient());
                            webView.setHorizontalScrollBarEnabled(false);
                            webView.loadData(html, "text/html; video/mpeg", "UTF-8");

                        } 

You need to put String url path in src like :

 String videoPath="http://api.thingspeak.com/channels/31592/charts/1?width=450&height=260&results=60&dynamic=true\\";

 String html = "<iframe width=\"450\" height=\"260\" style=\"border: 1px solid #cccccc;\" src=\""+videoPath+" ></iframe>";

if videoUrl is null or not valid then your page is not load then you need to hide webView

Here is code :

private boolean isValidUrl(String url) {
      Pattern p = Patterns.WEB_URL;
      Matcher m = p.matcher(url.toLowerCase());
      if(m.matches())
         return true;
      else
        return false;
}

then after load it into webView

 webview.getSettings().setJavaScriptEnabled(true);
if(videoPath!=null && isValidUrl(videoPath)
{
mWebView.setVisibility(View.VISIBLE); 
webview.loadData(html, "text/html", null);
    }

else
webview.setVisibility(View.GONE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM