1

I have a webview, which displays mobile version of site. I've made "switch", which allows user to switch to full version of site, if he wants. So at first user goes to site's mobile version and after that he may toggle "switch" and site's full version is loaded.

What's happening now: For some sites just changing user-agent is enough and they are loaded as from PC, when "switch" is toggled. But some sites are still able to detect, that I've entered from mobile device and still show me mobile version.

How can I tell ALL sites, that "I" am not mobile device, but a PC? Something like:

webView.getSettings().iAmPC(true);    

P.S: For example: Opera mobile for Android (and Firefox) have this functionality (if I choose "Desktop" in preferences, EVERY site gives me it's full version). Android default browser 2.3.6 - not.

P.P.S: It will be also useful, if you know how to achieve it even not in webview.

Update: It seems that X-WAP-Profile header should be changed, but still haven't found a solution. There is a kind of solution mentioned here but it seems to be unusable in-app.

P.P.P.S: My app has root access, so, solutions, which require root access are also accepted

Tried shouldOverrideUrlLoading with random or empty Accept header - no effect.

Community
  • 1
  • 1
janot
  • 13,578
  • 1
  • 27
  • 57
  • 1
    sometimes the webview includes X-WAP-Profile header, some websites detect using this, but i am not sure if we can change this header. – nandeesh Dec 13 '12 at 08:56
  • @nandeesh thanks, very useful info, I'll update my question according with it – janot Dec 13 '12 at 09:46

2 Answers2

1

Some websites query the navigator object with a script to check for the browser brand/version. Opera overrides that, and you might want, too.

Alexey Feldgendler
  • 1,792
  • 9
  • 17
  • Sorry for my ignorance, @AlexeyFeldgendler, but can you explain a bit deeper how to "override `navigator` object or specify the direction, where I can read more about it? I've tried to find this information independently - unsuccessfully. – janot Nov 26 '12 at 06:33
  • I don't know. It's possible that WebKit doesn't let you do that at all. I just know that this is what Opera does. – Alexey Feldgendler Nov 26 '12 at 13:11
0

x-wap-profile header is added in FrameLoader of the Webkit. So changing the firmware would be required to remove this header.

What you could do is try to have your own httpclient and fetch the content yourself. This has been tried on this post

Edit: Updated.

DefaultHttpClient client = new DefaultHttpClient();
comments.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url){

                String content = "";
                try {
                   content = getUrlContent(url)
                } catch (Exception e) {
                   e.printStackTrace();
                }
                view.loadDataWithBaseURL("BaseWebUrl", content, "text/html", "utf-8", "");
                return true;
            }
        });


    synchronized String getUrlContent(String url) {


        // Create client and set specific user-agent string
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(url);
        //request.setHeader("User-Agent", sUserAgent);

        try {
            HttpResponse response = client.execute(request);

            // Check if server response is valid
            StatusLine status = response.getStatusLine();
            if (status.getStatusCode() != HTTP_STATUS_OK) {
               return "Error";
            }

            // Pull content stream from response
            HttpEntity entity = response.getEntity();
            return EntityUtils.toString(entity)
    }
}
Community
  • 1
  • 1
nandeesh
  • 24,740
  • 6
  • 69
  • 79
  • Sorry, if too casual question, but Eclipse shows me following error `The method httpGet(String) is undefined for the type DefaultHttpClient` – janot Dec 16 '12 at 15:51
  • It seems to be close. Some pages are loaded perfectly. But some pages are loaded only partially. And some sites are still able to detect mobile device => load mobile version (I've additionally checked them in opera mobile - it loads their full versions correctly). – janot Dec 17 '12 at 08:24
  • try uncommenting the set useragent line and use any desktop useragent. Also take a tcpdump and check if any other headers are being sent – nandeesh Dec 17 '12 at 08:28
  • Using your own httpclient is not the best way, I am not sure if it handles retries, redirects and other such things. you might have to do it yourself – nandeesh Dec 17 '12 at 08:38
  • 1
    "try uncommenting the set useragent line and use any desktop useragent" - no effect. It seems that achieving this target that way is like creating my own webbrowser... Thanks for your help, I'll continue my attempts to achieve it a bit later, bounty will be yours. – janot Dec 18 '12 at 16:52