DEV Community

Dênis Mendes
Dênis Mendes

Posted on

Append a new User-Agent to WebView in Android

Sometimes you need to pass another user-agent when opening a URL in the Webview, so here how to do it in Android app:

String userAgent = String.format(
   "%s %s/%s",
   this.webView.getSettings().getUserAgentString(), 
   "Your Custom User-Agent", 
   BuildConfig.VERSION_NAME
);

this.webView.getSettings().setUserAgentString(userAgent);
webView.loadUrl(url);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)