獲取 Windows Phone 的 User-Agent 字串
[程式碼] 使用方法
01 |
public partial class HomeView
: PhoneApplicationPage |
02 |
{ |
03 |
public HomeView() |
04 |
{ |
05 |
InitializeComponent(); |
06 |
Loaded
+= HomeView_Loaded; |
07 |
} |
08 |
|
09 |
private void HomeView_Loaded( object sender,
RoutedEventArgs e) |
10 |
{ |
11 |
UserAgentHelper.GetUserAgent( |
12 |
LayoutRoot, |
13 |
userAgent
=> |
14 |
{ |
15 |
//
TODO: Store this wherever you want |
16 |
ApplicationSettings.Current.UserAgent
= userAgent; |
17 |
}); |
18 |
} |
19 |
} |
[程式碼] 工具類
01 |
public static class UserAgentHelper |
02 |
{ |
03 |
private const string Html
= |
04 |
@"<!DOCTYPE
HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN""> |
05 |
|
06 |
<html> |
07 |
<head> |
08 |
<script
language=""javascript"" type=""text/javascript""> |
09 |
function
notifyUA() { |
10 |
window.external.notify(navigator.userAgent); |
11 |
} |
12 |
</script> |
13 |
</head> |
14 |
<body
onload=""notifyUA();""></body> |
15 |
</html>" ; |
16 |
|
17 |
public static void GetUserAgent(Panel
rootElement, Action< string >
callback) |
18 |
{ |
19 |
var
browser = new Microsoft.Phone.Controls.WebBrowser(); |
20 |
browser.IsScriptEnabled
= true ; |
21 |
browser.Visibility
= Visibility.Collapsed; |
22 |
browser.Loaded
+= (sender, args) => browser.NavigateToString(Html); |
23 |
browser.ScriptNotify
+= (sender, args) => |
24 |
{ |
25 |
string userAgent
= args.Value; |
26 |
rootElement.Children.Remove(browser); |
27 |
callback(userAgent); |
28 |
}; |
29 |
rootElement.Children.Add(browser); |
30 |
} |
31 |
} |
相關文章
- 如何獲取 alter 裡面的字串?字串
- Windows Phone SDK 8/8.1 官方下載Windows
- Java String類,字串常量池,建立方法,字串的獲取,擷取,轉換,分割。Java字串
- Rust中如何獲取最大字串?Rust字串
- 獲取Windows遠端桌面埠Windows
- 獲取母字串中某個子字串的某個確定的index值字串Index
- mssql sqlserver 從指定字串中獲取數字的方法SQLServer字串
- Windows Phone應用效能監控與分析技巧Windows
- 根據屬性字串獲取屬性值字串
- 獲取一個字串中出現最多的字元和他的個數字串字元
- Python input()函式:獲取使用者輸入的字串Python函式字串
- Scrapy使用隨機User-Agent爬取網站隨機網站
- windows獲取實際cpu speed(非物理)Windows
- 獲取C/C++字串、字元陣列長度C++字串字元陣列
- 【SQL】SQL解惑-如何從字串中獲取IP地址SQL字串
- 無影雲電腦獲取windows密碼的方法Windows密碼
- Windows系統安全獲取重要資訊的方法(一)Windows
- windows10系統設定和使用Your Phone應用的方法Windows
- vmi:獲取 windows 系統硬體資訊Windows
- php 根據給定字串時間獲取時區PHP字串
- C#獲取Windows10螢幕的縮放比例C#Windows
- 正規表示式獲取兩個字元之間的字串資訊字元字串
- 微軟官方Windows Phone、Windows 10 Mobile裝置恢復工具被曝遭到移除微軟Windows
- Win10系統如何禁用Windows Phone-PC連結Win10Windows
- 深入理解Windows Phone 8.1 UI控制元件程式設計WindowsUI控制元件程式設計
- windows C++ 獲取使用者桌面路徑WindowsC++
- GUID獲取16位19位22位的唯一字串GUI字串
- 字串擷取字串
- 網頁重寫字串val()方法的擴充套件獲取安全引數String網頁字串套件
- MySQL 字串函式:字串擷取MySql字串函式
- lua獲取字串中單引號之間的字串字串
- Windows系統下透過命令列獲取程序指標Windows命令列指標
- 獲取字串中的所有漢字字串
- Codeforces 1017 CThe Phone Number
- 如何在Java中獲取Windows和Linux/Mac系統上的桌面路徑JavaWindowsLinuxMac
- 在Windows, Mac, Linux三種系統中分別獲取wifi密碼的方式WindowsMacLinuxWiFi密碼
- php一句話獲取獲取檔案目錄的方法PHP
- Winrm 獲取遠端windows伺服器 cpu、磁碟、記憶體Windows伺服器記憶體
- windows10系統如何一鍵獲取鎖屏聚焦桌布Windows