Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView with an IFRAME android

I want to load an HTML <IFRAME> inside an WebView, but I don't know why, it is not able to do so.

I am using following code to load <IFRAME>

webView.loadData("<iframe src=\"http://www.google.com\"></iframe>", "text/html",
                "utf-8");

Here's what I have tried.

WebSettings webViewSettings = webView.getSettings();
webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webViewSettings.setJavaScriptEnabled(true);
webViewSettings.setPluginsEnabled(true);
webViewSettings.setBuiltInZoomControls(true);
webViewSettings.setPluginState(PluginState.ON);

I have mentioned the internet permission:

<uses-permission android:name="android.permission.INTERNET" />

I have also tried settings the WebViewClient with shouldOverrideUrlLoading always returning false.

But it just isn't working.

I have tried this with diffrent sites, i.e. sites other than, google.com.

I am testing this on, Samsung Nexus S running ICS 4.0.3

like image 206
Shardul Avatar asked Jan 21 '12 17:01

Shardul


1 Answers

Try with the below code:

webView.setInitialScale(1);
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;

Log.e(SimpleBillsConstants.SIMPLE_BILLS, width + "-" + height);

String data_html = "<!DOCTYPE html><html> <head> <meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"target-densitydpi=high-dpi\" /> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> <link rel=\"stylesheet\" media=\"screen and (-webkit-device-pixel-ratio:1.5)\" href=\"hdpi.css\" /></head> <body style=\"background:black;margin:0 0 0 0; padding:0 0 0 0;\"> <iframe style=\"background:black;\" width=' "+width+"' height='"+height+"' src=\""+VIDEO_URL+"\" frameborder=\"0\"></iframe> </body> </html> ";

webView.loadDataWithBaseURL("http://vimeo.com", data_html, "text/html", "UTF-8", null);
like image 94
Vinayagam.D Avatar answered Sep 28 '22 04:09

Vinayagam.D