简体   繁体   English

Android如何在android iframe webview中传递url?

[英]Android how to pass url in android iframe webview?

Android how to pass url in android iframe webview ? Android如何在android iframe webview传递url? I'm trying to pass url dynamically form server so what i do 我正在尝试动态地传递url服务器,所以我做的

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 : 你需要在src放置String url路径,如:

 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 如果videoUrl为null或无效,则表示您的页面未加载,则需要隐藏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

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

else
webview.setVisibility(View.GONE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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