android - Webview not showing content properly of Facebook URL - android

I have an application in which I'm passing this URL to WebView.
Facebook URL
But the WebView is not displaying the page correctly.
The default android browser is displaying the content correctly.
Code
WebSettings wsettings = webView.getSettings();
wsettings.setBuiltInZoomControls(false);
wsettings.setSupportZoom(false);
wsettings.setJavaScriptEnabled(true);
webView.setScrollbarFadingEnabled(false);
webView.setHorizontalScrollBarEnabled(true);
wsettings.setUseWideViewPort(true);
wsettings.setLoadWithOverviewMode(true);
wsettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
wsettings.setAppCacheEnabled(true);
wsettings.setAppCachePath("");
wsettings.setUserAgentString("AndroidWebView");
wsettings.setDatabaseEnabled(true);
wsettings.setDomStorageEnabled(true);
webView.clearCache(true);
Please see the below screen shot for reference.

I have found the solution for this by removing the below code.
wsettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
wsettings.setAppCacheEnabled(true);
wsettings.setAppCachePath("");
wsettings.setUserAgentString("AndroidWebView");
wsettings.setDatabaseEnabled(true);
wsettings.setDomStorageEnabled(true);
webView.clearCache(true);

Add this options in your WebView code:
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
if (Build.VERSION.SDK_INT < 8) {
mWebView.getSettings().setPluginsEnabled(true);
} else {
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
}
In my case, Facebook works perfectly.
Regards

Related

How do I .loadUrl variable instead of url?

I load my ad banner page inside of app like
WebView reklam1goruntule = (WebView) findViewById(R.id.reklam1);
WebSettings webSettings = reklam1goruntule.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
reklam1goruntule.loadUrl("http://mywebside.com/adbanner.html");
reklam1goruntule.setWebViewClient(new WebViewClient());
I would like to use change this url any time using by firebase.And load to new url.So I'll use like..
myRef.child("Ads").child(mAuth.getCurrentUser().getUid()).child("Banners").setValue("Ad240url");
But how do ı need replace this ?
reklam1goruntule.loadUrl("http://mywebside.com/adbanner.html");
it's need to looks like
reklam1goruntule.loadUrl("Ad240url");

zoom is not working in webView on android application

When I open pptx file through this link zoom is not working in android webview.
Here is the code that i'm using:
WebSettings setting = wView.getSettings();
setting.setBuiltInZoomControls(true);
setting.setSupportZoom(true);
In the OnCreate method, just put
webView.getSettings().setBuiltInZoomControls(true);
And it's working fine here.
For enable zoom option add this line of code.
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);

Android Webview doesn't load

I have a problem with Android Web view.
The slider work fine with Apple but doesn't load on Android WebView.
Can anyone help? www.pgc-usa.net/ivynails
Thanks
I think I know. Web views in Android by default do not have JavaScript enabled. This is because there is someway it can do harm to the app. To enable it though it takes two lines
WebSettings webSettings = yourWebview.getSettings();
yourWebview.setJavaScriptEnabled(true);
You can also set it so that links that are clicked open in the web view. ( Otherwise they open in browser.) to add this you just add
yourWebview.setWebViewClient(new WebViewClient());
All that together will make it come to this:
WebView yourWebview = (WebView) findViewById(R.id.myWebview);
yourWebview.loadUrl("http://www.pgc-usa.net/ivynails");
WebSettings webSettings = yourWebviewgetSettings();
webSettings.setJavaScriptEnabled(true);
yourWebview.setWebViewClient(new WebViewClient());
You can find out more by visiting this page on the Android developer site by clicking this link.

Android WebView cache doesn't expire

in my Android App I use a WebView and got a problem with caching.
After a file is cached the WebView just keeps it forever (or at least until I delete the cache manually).
In the Apache Access-Log I see that the WebView doesn't send requests once the file is cached. How can I setup the WebView to send requests for checking if the file is expired by using common ETags and HTTP-Code 304? On a desktop browser(Firefox, Chrome) the caching works as expected.
Here is my code:
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new EWebViewClient(this));
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.setWebChromeClient(new EWebChromeClient(this));
webView.setBackgroundColor(Color.argb(1,0,0,0));
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
webView.loadUrl(url);
EWebViewClient only overwrites: "shouldOverrideUrlLoading, onPageFinished, onLoadResource, onReceivedError"
I really appreciate any help you can provide.

Android Webview - Webpage must fit the screen

I have tried the following to fit the web page based on the device screen size. But after code the text fields and drop down buttons are not working. Can anyone help me?
WebView myWebView;
#SuppressWarnings("deprecation")
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
myWebView.getSettings().setPluginState(PluginState.ON);
myWebView.loadUrl("http://m.immigrer.com/potentiel");
myWebView.setWebViewClient(new myWebViewClient());
}
The page you linked to is designed to fit the screen by default. You should try setting setUseWideViewPort(true) as that makes the WebView pay attention to the site's viewport meta tag. Also, the LayoutAlgorithm setting might be messing things up: try using LayoutAlgorithm.NORMAL.
Use downloadListener or use onPageStarted() and check if your webview ends with '.pdf'.(Assuming your URL, which contains a PDF is ending with '.pdf'. Else check any qualifier you are using in all your URLs where you expect a PDF to download, and then pass on that URL to AsyncTask to download.
Tested the link with the following settings:
WebSettings s = getSettings();
s.setBuiltInZoomControls(true);
s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
s.setUseWideViewPort(true);
s.setLoadWithOverviewMode(true);
s.setSavePassword(true);
s.setSaveFormData(true);
s.setJavaScriptEnabled(true);
s.setRenderPriority(RenderPriority.HIGH);
s.setPluginState(android.webkit.WebSettings.PluginState.ON_DEMAND);
// enable navigator.geolocation
s.setGeolocationEnabled(true);
s.setGeolocationDatabasePath("");
// enable Web Storage: localStorage, sessionStorage
s.setDomStorageEnabled(true);
I was able to use text fields and drop down buttons. Some settings are irrelevant but hey it works

Categories

Resources