This is my url that I want to open in webview but its show different UI rather than the chrome or mozila browser.
http://www.nigeriatoday.ng/
Try to open it in webview and browser and you know the difference.
I need same like browser. Please help me. It would be appreciatable.
WebSettings settings = webvw.getSettings();
webvw.setWebViewClient(new WebViewClient());
webvw.setWebChromeClient(new WebChromeClient());
webvw.getSettings().setJavaScriptEnabled(true);
webvw.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webvw.loadUrl(Url);
Thanks
As Murat said, You have different look and feel for Mobile version and desktop version.
If you have any specific requirement that you need to display Web content with desktop version on webview, then you can use below code.
String ua = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
webvw.getSettings().setUserAgentString(ua);
You can see below output...
Related
I want to use whats app in Webview android. I've already tried to set user agent but it didn't help.
Is there any way that whats app recognize webview as Chrome browser.
String newUA= "";
newUA= "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.181 Safari/537.36";
binding.webView.getSettings().setJavaScriptEnabled(true);
binding.webView.loadUrl("https://web.whatsapp.com/");
binding.webView.getSettings().setUserAgentString(newUA);
try to set User Agent BEFORE calling URL load (make all settings-related calls before any page load try)
I have an Android browser that uses the WebView. I allow my users to switch the user agent and I've added a few user agents, one of which is the desktop mode user agent Chrome uses. The desktop mode user agent works great on some sites but on others it doesn't, however Chrome can request a desktop site on those websites just fine.
So what else is Chrome doing?
Thanks.
It also ignores any viewport meta tag and uses the default width of 980px. Source: https://crrev.com/5252baa9fbff3f1ffda51a4390cdf43070af22d7
Some web sites switch between desktop and mobile purely based on user agent sniffing, but others just use responsive CSS (and reasonable event handlers). You can identify a responsive site from desktop chrome by enabling device emulation in Chrome's developer tools: The site will immediately transform into the mobile version.
WebView doesn't seem to support this desktop mode exactly. Setting setUseWideViewPort(true) and setLoadWithOverviewMode(true) might be similar, but I'm not sure. See Force webview to display desktop sites, which links to a WebView subclass that provides a lot of additional functionality.
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return false;
}
});
webview.getSettings().setMinimumFontSize(12);
webview.setInitialScale(150);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(false);
webview.getSettings().setSupportZoom(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setDisplayZoomControls(false);
webview.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webview.setScrollbarFadingEnabled(false);
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
String newUA= "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19";
webview.getSettings().setUserAgentString(newUA);
webview.loadUrl( ipAddress + "/wordpress/resume/");
webview.reload();
Got it to load Wordpress site in desktop mode because one plugin like to pull columns.
I am using android webview to show an article .
I need to re-wrap the text whenever the user make a zoom .
I'm using android lollipop .
I found this solution but it is not working for me ?
String userAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
settings.setUserAgentString(userAgent);
Any trick to do that?
Is there is a way to reload the webview whenever the user make a zoom so it will be loaded wrapped to the new size?
You have to do that in javascript function and call that through the javascript client of webview.
for details visit:
android webview basics
I have a web content which is a collection of html ,js and static content like images, videos etc.
When I host the web content in a web server in some other system. I can render them from my Android stock browser (Using HTC One 4.4.2) but not from Chrome browser.
If I take the content locally and serve it from an embedded web server (NanoHTTPD) in my application. (This is my actual use case) the videos in my web content are not rendering.
Same problem happens when I am trying to load the same content as loadURL in my web view. So its seem its not the problem of how I am using the NanoHTTP server in my application and serving my content. Problem seems to be the configuration or rendering of Web View otherwise serving it from my system server would have worked.
In my web view I have enabled all the settings.Below is the code for the confugration of Web view.
webView = (WebView) findViewById(R.id.webView);
progressBar = (ProgressBar) findViewById(R.id.progressBarForWebView);
WebSettings webViewSettings = webView.getSettings();
webViewSettings.setJavaScriptEnabled(true);
webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webViewSettings.setPluginState(PluginState.ON);
webViewSettings
.setUserAgentString("Mozilla/5.0 (Linux; U; Android 4.4.2; en-in; HTC_One_dual_sim Build/KOT49H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
String userAgentString = webViewSettings.getUserAgentString();
webView.getSettings().setAllowFileAccess(true);
webView.setSoundEffectsEnabled(true);
webView.setWebViewClient(new MyWebViewClient());
Even set the user agent to the string received from the stock browser. I read from the https://developer.chrome.com/multidevice/webview/overview that from 4.4 the rendering engine of Chrome and WebView is same.
Since my content does not run on Android Chrome but on Android Stock browser, would the web view also not render my content even if I change my user agent for it ?
Any other ways to render my content ?
Cheers,
Saurav
I am trying to open twitter page begining with https in webview in android. But it is not opening and blank screen is coming with continous loading. Screen shot is below
Edit: In main webview I have link to twitter page https://twitter.com/mytwitterpage. On clicking that link that twitter url is opening in webview. I noticed that onPageFinished method of WebViewClient is called 2 times one time for https://twitter.com/mytwitterpage and second time for https://mobile.twitter.com/#!/mytwitterpage.
Anyone know what is wrong here?
Thanks in advance.
Ok done by adding below line in my code
webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
I got it from this post at stackoverflow Problems loading mobile.twitter in webview.
wv.getSettings().setDomStorageEnabled(true);
This worked for me!
Are you hitting a https:// page? If so, try setting a WebViewClient on your webview and override onReceivedSslError and see if there something wrong.
Twitter changed some certificate stuff recently, if you're hitting twitter.com/... try hitting api.twitter.com/...
Just add this code below webview. It solved my problem.
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(this, "TwitterDownloader");