Issue to run javascript in webview with Android version 4.0.3 - android

I'm doing some stuffs. I got unbelievable issue with Webview. I am not able to run javascript with webview in android version 4.0.3. I'm calling webpage that contains java script. I am able to run that with all the version remaining 4.0.3. Is it global issue with this particular version or I'm doing something wrong?
Here is my code:
mMainWebView = (WebView) findViewById(R.id.MainWebView);
mMainWebView.getSettings().setUserAgentString("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.36 (KHTML, like Gecko) Chrome/13.0.766.0 Safari/534.36");
mMainWebView.getSettings().setJavaScriptEnabled(true);
mMainWebView.getSettings().setPluginState(PluginState.ON);
mMainWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(
false);
mMainWebView.setWebChromeClient(new MyWebChromeClient());
mMainWebView.loadUrl("http://mypage.aspx?Go=Go&IMEI=11111111&MAC=00:00:00:00:00:00");
My Javascript at webpage:
javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl11", "", false, "", "http://mypage.com", false, true))
Please help me with your best suggestions.
Thanks,

Related

Whats app doesn't support Webview android

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)

Webiew load URL issue

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...

Web Content not rendering on Android Web view

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

Why is Android WebView loading webpage differently than the default browser?

I'm having a problem related to this one. Basically, the same WebView displays differently on Android 2.2 and Android 4.0. In Android 4.0 it displays the mobile version of the website, while in 2.2 it displays the web version of it. Also, in the default web browser on Android 2.2 it displays the mobile version like it should. Is this a known bug? I have tried different settings for the webview so far but I always get this problem, on real devices and in the emulator.
I have attached 2 screens to see the difference. And here is the code. Note that I have tested pretty much all the combinations for the settings and to no use.
`
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);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.setInitialScale(1);
webView.getSettings()
.setUserAgentString(
"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");
webView.loadUrl("http://www.fernbus24.de/");
}`
Why is the display different? What does the WebView on Android 4.0 have that the other one doesn't?
It's not an Android bug, it's the website and the way it recognizes mobile devices. I tried google.com and facebook.com and they loaded the mobile version without problems.

Android Webview issue for Twitter even with DomStorageEnabled enabled

I have tested the following issue on Galaxy Note 2.3, Sony tablet 3.2 as well as Galaxy Y 2.3 and the issue is 100% reproducable. As suggested on many threads , webview.getSettings().setDomStorageEnabled(true); does the trick. But i am observing that first time when the Webview loads twitter.com , its going blank . Then if i say webview.reload() or again call load Url then twitter loads correctly every time until i exit the app (Preferably Force stop from settings) . This issue is happening for all sites which give WebConsole error. If i reload the same site , then its loading correctly. Is anyone having the same issue ?
Following is a small snippet of code i use.
webview = new Webview(activity.context);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setDomStorageEnabled(true);
webview.loadUrl("http://www.twitter.com");
Hardcoding the Useragent as suggested on other threads solved the problem
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");
What will be the disadvantages of this dirty trick ? Will it affect the sites loading on a tablet ?
Will users be able to go to the desktop site if they want to ?

Categories

Resources