Issue
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 the URL and then use it in the web view loadUrl method.
But it seems like the Web View is making a call different than Chrome and my guess is that is not telling to the server that is a "Chrome Browser".
So if I open the page in Chrome directly clicking on a Hyper Link in for example in an Email a got this page:
This is exactly the behavior that I'm expecting.
But if I call the same URL in my Web View i got this page:
Right now I'm using just this code to keep it clean:
webview = (WebView) findViewById(R.id.webView);
webview.setWebChromeClient(new WebChromeClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(tValue);
But i have tried all this, and nothing seems to tell to TripAdvisor to behave like it was a Chrome call:
webview = (WebView) findViewById(R.id.webView);
webview.setWebViewClient(new WebViewClient());
webview.setWebChromeClient(new WebChromeClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webview.clearCache(true);
webview.clearHistory();
webview.loadUrl(tValue);
I'm doing exactly the same in my iOS app and the UIWebView behaves or tells to the server the same as it was a call made in Safari.
Is there a way to change some header or something to tell the server that my web view is a "Chrome Browser"??
Thanks in advance.
UPDATE 1:
Thanks to the answer of Dominik K i tried all the user agents he suggested and still nothing work.
So it occurs to me to test the agent of both and in effect they are different, but even using the one that is using Chrome, there is no satisfying result.
I think that there is no good answer to this one.
Solution
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(new WebChromeClient());
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:
iOS
Happy coding and thanks for the help.
Answered By - Stornu2
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.