Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To change the user agent you need to send a custom User-Agent: header with your HTTP request. Assuming you're using the Android org.apache.http.client.HttpClient class, you have two options:</p> <ol> <li>Set the user agent header on each request. You do this by calling setHeader() on your HttpRequest (HttpPost, HttpGet, whatever) object after you create it:</li> </ol> <pre> HttpGet get = new HttpGet(url); get.setHeader("User-Agent", myUserAgent); </pre> <ol start="2"> <li>Change the default User Agent parameter, which will affect all future instances of that HttpClient class. You do this by reading the HttpParams collection from your client with getParams() then updating the user agent using setParameter():</li> </ol> <pre> DefaultHttpClient http = new DefaultHttpClient(); http.getParams().setParameter(CoreProtocolPNames.USER_AGENT, myUserAgent); </pre> <p>If you want to append instead of replace the user agent, you can read the existing one first, change it, and set it back using either of the above methods.</p> <p>EDIT:</p> <p>Since you said you're using the WebView view you will need to use the WebSettings customization point there. It's basically the same process. Before you call whichever load() method (loadUrl, loadData, etc) you do set the user agent. The changed user-agent will persist as long as that instance of the WebView is around, so you'd do this in the onCreate() of your Activity:</p> <pre> view = (WebView)findViewById(R.id.webview); view.getSettings().setUserAgentString(myUserAgent); </pre> <p>Again, if you want to append instead of replace, use getUserAgentString() to read it, then update it and set it back again. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload