如何使用 c# 在 windows phone 和 windows 8.1 中找到 device/tablet 的用户代理?

How to find user-agent of device/tablet in windows phone and windows 8.1 using c#?

我想使用 c# 查找设备 运行 我的应用程序的 UserAgent。谁能建议如何使用一些代码找到它。我做了一些研究,其中大部分都显示了硬编码字符串或使用 java-script 的实现。但我想用 c# 找到它。请有人提出一个快速简便的解决方案。

此代码需要将 webBrowser 控件添加到页面,

public partial class HomeView : PhoneApplicationPage
{
    public HomeView()
    {
        InitializeComponent();
        Loaded += HomeView_Loaded;
    }

    private void HomeView_Loaded(object sender, RoutedEventArgs e)
    {
        UserAgentHelper.GetUserAgent(
            LayoutRoot,
            userAgent =>
                {
                // TODO: Store this wherever you want
                ApplicationSettings.Current.UserAgent = userAgent;
               });
    }
}

帮手

public static class UserAgentHelper
{
private const string Html =
    @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"">

    <html>
    <head>
    <script language=""javascript"" type=""text/javascript"">
        function notifyUA() {
            window.external.notify(navigator.userAgent);
        }
    </script>
    </head>
    <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);
}
}