How to get desktop version of webpage under Android?


Ask by : FalconIA November 03, 2012 17:57

I try to get webpage using HttpURLConnection, and get a result of mobile version page.

Now I want to get a desktop version page, and try to use: System.setProperty("http.agent", "Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0"); or setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0"); But I still get a result of mobile version page.

Does anyone know how to get a desktop version source code of webpage instead the mobile version?

PS: My Android is 2.3.7

View original question

Answer by : Sarath Kumar SivanNovember 03, 2012 17:57

You have to set the User-Agent of your connection to pretend that it's a desktop client.

As you are using the HttpUrlConnection, you can do something like:

URL url = new URL( "http://www.google.co.in/" );
HttpUrlConnection connection = (HttpUrlConnection) url.openConnection();
connection.setRequestProperty( "User-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) 
View original answer