Set/Change changing the WebView user agent in Android

Viewed 7387

I have a website which should supposedly only using WebView in my app, otherwise my website redirects the user to a page from where he can download my App.

So, how can I change this UA in WebView?

Also, what are the possible issues which can arise from this?

2 Answers

You can use setUserAgent from android.webkit.WebSettings, simple example:

WebView myWebView = (WebView) findViewById(R.id.myWebView);

WebSettings myWebSettings = myWebView.getSettings();
myWebSettings.setUserAgentString("Foo/Bar"); # Set your custom user-agent

Also, what are the possible issues which can arise from this?

Depends on what you did, userAgent is not "perfect", but was created for this purpose, identify the browser.

Related