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)

Image of Datadog

Get the real story behind DevSecOps

Explore data from thousands of apps to uncover how container image size, deployment frequency, and runtime context affect real-world security. Discover seven key insights that can help you build and ship more secure software.

Read the Report

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay