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)

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools 🔁

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay