3

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");

                        } 
AskNilesh
  • 67,701
  • 16
  • 123
  • 163

1 Answers1

0

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);
Adil
  • 812
  • 1
  • 9
  • 29
  • this error ---- @AD 10 W/AudioCapabilities: Unsupported mime audio/evrc Unsupported mime audio/qcelp W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc W/AudioCapabilities: Unsupported mime audio/qcelp Unsupported mime audio/evrc W/VideoCapabilities: Unsupported mime video/mpeg2 Unsupported mime video/mpeg2 – Soniya Joshi May 17 '18 at 12:02
  • try with this webView.loadData(html, "text/html", "UTF-8"); and can you please provide video url? – Adil May 17 '18 at 12:09
  • refer this may helps -https://stackoverflow.com/questions/14156411/loading-youtube-video-through-i-frame-in-android-webview – Adil May 17 '18 at 12:10
  • how to change visibility of webview in android webView.setVisibility(View.GONE); this is not orkin its still carving space of screen – Soniya Joshi May 17 '18 at 12:57
  • webView.setVisibility(View.GONE); – Soniya Joshi May 17 '18 at 13:01
  • okay tell me, when you want to hide webview? on button click? and post your whole class code – Adil May 17 '18 at 13:02
  • i am getting the url from server so when the url is null then do that – Soniya Joshi May 17 '18 at 13:03
  • is that work if(ResponseProduct.video!=null && isValidUrl(ResponseProduct.video)) – Soniya Joshi May 17 '18 at 13:24
  • did you check url is valid or not ? – Adil May 18 '18 at 04:53