Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Setting user agent of WebView custom renderer makes Navigated event fire twice on Xamarin Android

$
0
0

I would like to set a custom User Agent string on a Xamarin Forms WebView on iOS and Android. I am using a custom renderer for this on both platforms. The iOS version works fine, but on Android, the following code when placed in the OnElementChanged of the Android custom renderer causes the Navigated event of the WebView to fire twice, once when the WebView starts to load and once when it is actually completed. Commenting out the setting of the user agent causes the Navigated event to only fire once when the load is complete like it should. Is there another way to set the user agent on Android or is there some other way to get around what seems to be a bug here?

// get useragent
var userAgent = this.Control.Settings.UserAgentString;
if (!userAgent.Contains("MyApp"))
{
userAgent += " MyApp";
// set useragent
this.Control.Settings.UserAgentString = userAgent;
}


Viewing all articles
Browse latest Browse all 77050

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>