Webview is not loading facebook content - android

In my recyclerview I am loading webviews as items.
The Item webview may be twitter content, instagram or facebook.
my problem is that the facebook content is not loading in webview.
The html content and my binding part are given below
<iframe style="width:100%;height: 80vh;" allowfullscreen="true" allowtransparency="true" frameborder="0" height="316" scrolling="no" src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Fnarendramodi%2Fvideos%2F10159805167945165%2F&show_text=0&width=560" style="border:none;overflow:hidden" width="560"></iframe>
webView =(WebView)itemView.findViewById(R.id.web_view);
WebSettings settings = webView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webView.setFocusable(false);
webView.setClickable(true);
settings.setDomStorageEnabled(true);
settings.setJavaScriptEnabled(true);
settings.setAllowContentAccess(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLoadsImagesAutomatically(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
webView.loadDataWithBaseURL(null, myHtmlString, "text/html", "UTF-8", null);

Related

My Android WebView application shows error, works good on the browser(Chrome)

mWebView = findViewById(R.id.webView);
WebSettings settings=mWebView.getSettings();
//webview setting
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setLoadWithOverviewMode(true);
settings.setDefaultTextEncodingName("UTF-8");
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setLoadsImagesAutomatically(true);
settings.setUseWideViewPort(true);
settings.setAllowFileAccess(true);
String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
settings.setAppCachePath(appCachePath);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
settings.setAppCacheEnabled(true);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
mWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
mWebView.setWebViewClient(new WebViewClientClass());
mWebView.setWebChromeClient(new webChromeClient(this));
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.setAcceptThirdPartyCookies(mWebView, true);
and everything works fine on my web. But when I try to login to the web, it shows error page.
[SOLVED]
It was simply web page error. Web developer has solved the issue.

Twitter video not loading android webview

When playing twitter video in android web view it shows the message 'by playing this video you agree to the Twitter use of cookies' and video is not played after that.
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
} else
CookieManager.getInstance().setAcceptCookie(true);
}
webView.getSettings().setJavaScriptEnabled(true);
webView.setBackgroundColor(Color.parseColor("#ffffff"));
webView.loadDataWithBaseURL("file:///android_asset/", htmlTemplate, "text/html", "UTF-8", "");
JavaScript is disabled in a WebView by default.
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
UPDATED:
Use TweetView for Native Videos
Launching native video support for Twitter Kit
Call loadDataWithBaseURL instead of loadData, like this:
loadDataWithBaseURL("https://mywebsite.com", mContent, "text/html", "UTF-8", null);

Cannot load Google Map Url in Android WebView

I try to load the Google Map Url in a WebView with the following code:
String url = "http://maps.google.com";
WebView webview = (WebView) findViewById(R.id.webview);
//webview settings
webview.setPadding(0, 0, 0, 0);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient());
webview.loadUrl(url);
and it cannot be loaded (blank).
But the other urls (e.g. http://www.google.com) can be loaded without any problem.
Please help !

Android WebView fit content to screen

I'm trying to fit webview content with screen but it display very ugly and show different results, please see below link for screen capture :
http://postimg.org/image/jy0g268p1/0294ca52/
http://postimg.org/image/603z8qhab/e06b655e/
Please find below my code :
WebSettings settings = webView.getSettings();
settings.setMinimumFontSize(30);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
webView.loadData(htmlContent, "text/html", "UTF-8");
webView.setInitialScale(1);
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Kindly advise what should I do to fit content nicely?
Really appreciate for any kind help.
This worked for me:
webview.Settings.LoadWithOverviewMode = true;
webview.Settings.UseWideViewPort = true;
I think I have found my own solution, I put here for someone who need it in future.
I just create one method to change head of html :
public static String changedHeaderHtml(String htmlText) {
String head = "<head><meta name=\"viewport\" content=\"width=device-width, user-scalable=yes\" /></head>";
String closedTag = "</body></html>";
String changeFontHtml = head + htmlText + closedTag;
return changeFontHtml;
}
And I'm using it inside webview as follow :
public static void displayHtmlText(String htmlContent, String message,
WebView webView,
RelativeLayout videoLayout, LinearLayout standardLayout, LinearLayout webviewLayout){
WebSettings settings = webView.getSettings();
settings.setMinimumFontSize(18);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
webView.setWebChromeClient(new WebChromeClient());
String changeFontHtml = Util.changedHeaderHtml(htmlContent);
webView.loadDataWithBaseURL(null, changeFontHtml,
"text/html", "UTF-8", null);
webviewLayout.setVisibility(View.VISIBLE);
standardLayout.setVisibility(View.GONE);
videoLayout.setVisibility(View.GONE);
}
So my content in webview now is fit to device and can show nicely.
I have create my own method with set background color and font color also.
WebSettings settings = desc.getSettings();
settings.setMinimumFontSize(50);
desc.getSettings().setJavaScriptEnabled(true);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
desc.setWebChromeClient(new WebChromeClient());
String changeFontHtml = changedHeaderHtml(description);
desc.setBackgroundColor(context.getResources().getColor(R.color.all_app_bg_color));
desc.loadDataWithBaseURL(null, changeFontHtml,"text/html", "UTF-8", null);
desc.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:document.body.style.setProperty(\"color\", \"white\");"
);
}
});
public static String changedHeaderHtml(String htmlText) {
String head = "<head><meta name=\"viewport\" content=\"width=device-width, user-scalable=yes\" /></head>";
String closedTag = "</body></html>";
String changeFontHtml = head + htmlText + closedTag;
return changeFontHtml;
}

Android Webview Disable Form input Zoom

I've been having issues trying to get webview from stop zooming in when a user clicks a input field on webview. How can I keep webview from stop zooming in?
Heres my code:
wv = (WebView) findViewById(R.id.webView1);
WebSettings webSettings = wv.getSettings();
wv.setWebViewClient(new WebViewClient());
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(true);
wv.getSettings().setDisplayZoomControls(false);
wv.getSettings().setBuiltInZoomControls(false);
wv.getSettings().setSupportZoom (true);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setDefaultZoom(ZoomDensity.FAR);
String form = "<form action='demo_form.asp'><input type='text' name='email' style='font-size: 200%;width:78%;float:left'><input type='submit' value='Submit' style='float:right;width:20%;font-size: 200%'></form>";
String summary = "<html><body>"+form+"</body></html>";
wv.loadData(summary, "text/html", null);

Categories

Resources