constantin cara
constantin cara

Reputation: 21

Android WebView full page

I am creating an aplication that involves an WebView. The thing is that I want to load the full page and not the mobile one, so I have changed the User Agent. Nevertheless there are pages that loads the mobile version.

Here are two versions of code that I have tried:

1.webview.getSettings().setUserAgentString("Mozila ");
2. String DESKTOP_USERAGENT = webview.getSettings().getUserAgentString (); DESKTOP_USERAGENT = DESKTOP_USERAGENT.replace("Mobile ",""); webview.getSettings().setUserAgentString(DESKTOP_USERAGENT);

This are exemples of webpages that loads the mobile version in any cases:

http://www.jurnalul.ro http://www.androidzoom.com

1.Does anyone knows how I can trick the server and tell him I am using a desktop and not a mobile? 2.How does a website knows that I am using a mobile version?

Thank you very much, Razvan

Upvotes: 1

Views: 3084

Answers (2)

Thomas Dignan
Thomas Dignan

Reputation: 7102

The problem may be that if you are using a device that your carrier is routing all your HTTP requests through a proxy, and that the proxy is changing the User-Agent. Check on the other end, with your own server, using nc -l 80 -vvv that your request is indeed sending the User-Agent that you have modified.

EDIT: Some specific troubleshooting steps

  1. Forward a port 9090 on your router to your desktop machine or laptop.
  2. Download netcat
  3. Run netcat with the command "nc -l 9090 -vvv"
  4. In your Android application's WebView, make an HTTP request with the User-Agent you are injecting to http://your.ip.address:9090
  5. In the terminal you ran netcat, you will see the HTTP request dump in plain text. There you can check the HTTP header User-Agent to see if it has been changed by a proxy server or not.

You cannot test this stuff with Wireshark or Fiddler because it is happening in the WAN. You need to test it on the receiving end, either on a server, or on your own desktop machine.

Upvotes: 2

Voidcode
Voidcode

Reputation: 1259

webview.getSettings().setUserAgent(1);//for desktop 1 or mobil 0. 

Upvotes: 1

Related Questions