1
votes

I am trying to get a user agent of a window phone i am using this way to get it

private const string Html =
        @"
    <html>
    <head>
    <script language=""javascript"" type=""text/javascript"">
        function notifyUA() {
           window.external.notify(navigator.userAgent);
        }
    </script>
    </head>`enter code here`
    <body onload=""notifyUA();""></body>
    </html>";

public static void GetUserAgent(Panel rootElement, Action<string> callback)
    {
        var browser = new Microsoft.Phone.Controls.WebBrowser();
        browser.IsScriptEnabled = true;
        browser.Visibility = Visibility.Collapsed;
        browser.Loaded += (sender, args) => browser.NavigateToString(Html);
        browser.ScriptNotify += (sender, args) =>
        {
            string userAgent = args.Value;
            rootElement.Children.Remove(browser);
            callback(userAgent);
        };
        rootElement.Children.Add(browser);
    }

this is working fine in case of WP 8.0 but incorrect in case of WP 8.1

by code i am getting UA as

Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 630)

But from whatsmyuseragent.com

Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0;Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 630) like Gechko please help me ...

1
I suspect the user agent IS reported as Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 630) for backwards compatibility, but the whatsmyuseragent.com is smart enough to figure out the correct version. Can you verify which user agent version is sent to the website, using Fiddler?Erti-Chris Eelmaa
I have kinda the same issue, my WP8.1 reports the UA as WP8.0 so i can't tell them apart. Have you fou nd any way to do it?Teodor Sandu

1 Answers

0
votes

In our portal, we detect the calling device over the UAS. I have detected some problems with the WP 8.1 user agent string.
For WP with IE, set to mobile over the Internet, I receive the "meaningful" UAS:

Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 930) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537

Whereby, if IE mobile is set to "Desktop" or the portal is called over the Intranet, I receive:

Mozilla/5.0 (Windows NT 6.2; ARM; Trident/7.0; Touch; rv:11.0; WPDesktop; Lumia 930) like Gecko

So.. the effect was, that our portal has showed the mobile page to iOS, instead of the mobile page to WP.
The workaround was to query the UAS for "Windows Phone" before the query for iPhone.
It seems as MS tries, to be detected as mobile device on this way (if a page only queries for iOS and Android-devices), what is not nice.