Jump to content



Photo

Downloading a webpage is returning the desktop then the mobile

Answered Go to the full post android java html mobile user agent

  • Please log in to reply
2 replies to this topic

#1 thatguyandrew1992

thatguyandrew1992

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 22-January 09

Posted 06 July 2013 - 02:39

Hey all, I am working on an android app and when downloading a webpage, sometimes I get the mobile version, other times I get the desktop version. Is there some way I can send the user agent? I want to force desktop.

What can I do?

 

This is code I use to get the page


				Scanner sc = null;
				try{
					URL link = new URL(http://somepage.com); 
					sc = new Scanner(link.openStream());
					System.out.println("one");
				}
				catch(Exception e1){
					e1.printStackTrace();
				}	


Best Answer thatguyandrew1992 , 06 July 2013 - 06:58

So as far as I can tell, this was the solution

HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0");
Go to the full post



#2 OP thatguyandrew1992

thatguyandrew1992

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 22-January 09

Posted 06 July 2013 - 06:02

I found this, I am trying to use the third answer

http://stackoverflow...ge-with-android

Just need to find out what the desktop user agent is, I think



#3 OP thatguyandrew1992

thatguyandrew1992

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 22-January 09

Posted 06 July 2013 - 06:58   Best Answer

So as far as I can tell, this was the solution

HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0");