Skip to content Skip to sidebar Skip to footer

Webview Is Not Behaving Like Chrome

I'm trying to open a TripAdvisor URL in my web view, so the users can easily rate my client Hotel. So what I did was to open the TripAdvisor web site in the Phone Chrome App copied

Solution 1:

Well I have made it,

Thanks to the answer of Dominic K and a lot of testing I have found a not so elegant solution to this problem.

The goal was to view the "Leave a comment and rate" exactly like in an iOS device.

So at the end I have changed the user agent in the Android WebView to the one that use the iOS UIWebView.

The code in Android looks like this:

webview = (WebView) findViewById(R.id.webView);
webview.setWebChromeClient(newWebChromeClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setUserAgentString("Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.14 (KHTML, like Gecko) Mobile/12F70");
webview.loadUrl(tValue);

Here you have some screen shoots with the result:

ANDROID:

enter image description here

iOS

enter image description here

Happy coding and thanks for the help.

Solution 2:

Webviews are using the standard Android user agent.

This should fix things for you.

webview.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19");

More details on user agents: https://developer.chrome.com/multidevice/user-agent

Post a Comment for "Webview Is Not Behaving Like Chrome"