Android Webview Useragent

You must Login before you can answer or comment on any questions.

Is there any property or method to set the useragent for a webview, I know there is for the httpclient.

Alternatively, is there a way to take over the network side of the webview to route it through a httpclient.

I have a website that is iphone only, Want it on android, but can't change the site

3 Answers

Accepted Answer

You should be able to call setHeader('User-Agent','my user agent') on your XHR instance.

— answered 3 years ago by Jeff Haynie
answer permalink
3 Comments
  • I'm not quite following, is there a way to access the httpclient instance for the webview?

    — commented 3 years ago by Ryan Tregea

  • Yeah i've just double checked, the HTTPclient instance is what you meant, Yeah that's fine i can set it there, however i want the user to be able to access back and forward to the server with the faked user agent.

    So i need to set the header for a webview. Is there some undocumented methods before each page request that i could redirect with httpclient

    — commented 3 years ago by Ryan Tregea

  • OK - I see, you're talking about the webview and not an XHR client request. We'll have to look into the ability to change the UA for the internal WebView. Looks like it's possible looking at Javadocs for Android.

    I have opened a ticket for this.

    — commented 3 years ago by Jeff Haynie

I made the modules to set custom UserAgent string to your webview. Please check and use it if it helps you.

https://github.com/harukazepc/TiWebViewUserAgent

and, you may use Ti.UI.WebView#setUserAgent() at Titanium 1.8.

Yeah i've just double checked, the HTTPclient instance is what you meant, Yeah that's fine i can set it there, however i want the user to be able to access back and forward to the server with the faked user agent.

So i need to set the header for a webview. Is there some undocumented methods before each page request that i could redirect with httpclient

Your Answer

Think you can help? Login to answer this question!