I'm using a webview to open a website. The problem I'm getting is after user clicks on a button, it always get stuck to the Loading dialog and doesn't show the expected results. But in Google Chrome or custom tabs, it works perfectly fine. I'm not overriding onPageFinished(), onPageStarted() or any other webview method, they are as it is. These are my webview settings:
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.getSettings().setSupportMultipleWindows(true);
WebSettings settings = webView.getSettings();
settings.setDomStorageEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setAllowFileAccessFromFileURLs(true);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
String newUA= "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0";
webView.getSettings().setUserAgentString(newUA);
webView.clearFormData();
webView.getSettings().setSavePassword(false);
webView.getSettings().setSaveFormData(false);
webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(true);
Just wanted to know what settings could be different in custom tabs and my webview that's causing the issue. And I think it's probably not possible but still asking is there any way to imitate the browser settings of custom tabs for the webview so that I can check if it works that way
Related
Not showing menu in android app
In chrome and other browser it shows properly as below
Chrome showing proper menu
everything is enabled Dom, Javascript - code snippet as below.
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setWebViewClient(new WebViewClient());
webView.setWebViewClient(new Browser_Home());
webView.setWebChromeClient(new ChromeClient());
webSettings.setAllowFileAccess(true);
webSettings.setAppCacheEnabled(true);
i need help, my WebView not show website's video player(black square)
But, it is working on phone browser.
Also, i have tried to use some advanced webview from github, same result(balck square).
This my code
webView = (WebView) findViewById(R.id.webview);
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setAppCacheEnabled(true);
settings.setDatabaseEnabled(true);
settings.setSupportZoom(true);
settings.setDisplayZoomControls(true);
settings.setBuiltInZoomControls(true);
settings.setAppCachePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/cache");
settings.setDatabaseEnabled(true);
settings.setDatabasePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/databases");
webView.getSettings().setUserAgentString("wp-android-native");
//webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 4.1.1; HTC One X Build/JRO03C) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.58 Mobile Safari/537.31");
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
//webView.setInitialScale(100);
webView.loadUrl("http://onlinemoviesbox.com");
Can you please comment below line and check once , am able to play youtube video properly
// webView.getSettings().setUserAgentString("wp-android-native");
I am trying to show this link in android app in webview but the web loads in android device is different from showing in Google Chrome.
Whatsapp link is here :https://web.whatsapp.com/
I am using this code in android to load the above page but it does not load the same page.
mWebView .loadUrl("https://web.whatsapp.com/");// https://tekdude.blogspot.in/");
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
setContentView(mWebView );
You can Use This Code, It Worked For me!!
Copy this code to inside OnCreate Method!! You can edit code according to your requirement.
webView.loadUrl(YOUR URL HERE);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUseWideViewPort(true);
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Win64; x64; rv:46.0) Gecko/20100101 Firefox/68.0");
webView.getSettings().setGeolocationEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setNeedInitialFocus(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
//webView.getSettings().setBlockNetworkLoads(true);
webView.getSettings().setBlockNetworkImage(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.setInitialScale(100);
You can try with changing user agent of your web view.
Example:
String newUA= "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
mWebView.getSettings().setUserAgentString(newUA);
Check this link
Setting WebView to view Desktop Site and Not Mobile Site
Change the user agent of webview
like
String newUA= "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
mWebView.getSettings().setUserAgentString(newUA);
Alternatively you can also change the settings without changing user agent
webView = (WebView)findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
I'm trying to embed an HTML page in a webview. The page has some jquery and javascript. When an input field is clicked it brings out the jquery datepicker. It works well in the native browser but, doesn't work in the webview. I did set enableJavascript to true but still not showing. So I'm not sure how it works if opened in the native browser, but not if is in webview. Am I missing anything? Any help is appreciated. This is my code:
myWebView = (WebView) findViewById(R.id.webView);
//Enable Javascript
WebSettings webSettings = myWebView.getSettings();
webSettings.setLoadWithOverviewMode(true);
//Enable DOM Storage
webSettings.setDomStorageEnabled(true);
//Enable Zoom
webSettings.setBuiltInZoomControls(true);
//I was adviced to place some of this to handle page navigation:
myWebView.setWebChromeClient(new WebChromeClient());
myWebView.setWebViewClient(new WebViewClient());
//other settings
myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
myWebView.setScrollbarFadingEnabled(false);
//finally, load url
myWebView.loadUrl("https://www.mycustomurl.com");
You have to enable Javascript in your webview...
like this,
WebView.getSettings().setJavaScriptEnabled(true);
in your code, add this too..
webSettings.setJavaScriptEnabled(true);
I am loading .html file on Android Webview. That htmnl file contains textFields. So as the user taps over textfield our webview is getting zoom in. As a result my webpage getting widened (out of content )
I am using the code as:
WebSettings webSettings = m_webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(false);
webSettings.setLoadsImagesAutomatically(false);
webSettings.setUseWideViewPort(false);
webSettings.setDefaultZoom(ZoomDensity.FAR);
webSettings.setSupportZoom(false);
Please let me know if anything i am missing.
Thanks in advance
You need to add to your html:
It's also a good idea to add the next settings to your webview.
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
webView.setInitialScale(1);
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(false);
You need to change your code in order to set zooming controls in your app
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setLoadsImagesAutomatically(false);
webSettings.setUseWideViewPort(false);
webSettings.setSupportZoom(true);
Try using
webview.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);