與眾不同windows phone (23)

來源:互聯網
上載者:User

Device(裝置)之硬體狀態, 系統狀態, 網路狀態

介紹

與眾不同 windows phone 7.5 (sdk 7.1) 之裝置

硬體狀態

系統狀態

網路狀態

樣本

1、示範如何擷取硬體的相關狀態

HardwareStatus.xaml.cs

/*  * 示範如何擷取裝置的硬體資訊   */   using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls;    using System.Windows.Navigation; using Microsoft.Phone.Info;    namespace Demo.Device.Status {     public partial class HardwareStatus : PhoneApplicationPage     {         public HardwareStatus()         {             InitializeComponent();         }            protected override void OnNavigatedTo(NavigationEventArgs e)         {             lblMsg.Text = "";                /*              * DeviceStatus - 用於擷取相關的裝置資訊              */               lblMsg.Text += "裝置製造商:" + DeviceStatus.DeviceManufacturer;             lblMsg.Text += Environment.NewLine;                lblMsg.Text += "裝置名稱:" + DeviceStatus.DeviceName;             lblMsg.Text += Environment.NewLine;                lblMsg.Text += "實體記憶體總計:" + DeviceStatus.DeviceTotalMemory; // 單位:位元組             lblMsg.Text += Environment.NewLine;                lblMsg.Text += "系統分給當前應用程式的最大可用記憶體:" + DeviceStatus.ApplicationMemoryUsageLimit; // 單位:位元組             lblMsg.Text += Environment.NewLine;                lblMsg.Text += "當前應用程式佔用記憶體的當前值:" + DeviceStatus.ApplicationCurrentMemoryUsage; // 單位:位元組             lblMsg.Text += Environment.NewLine;                lblMsg.Text += "當前應用程式佔用記憶體的高峰值:" + DeviceStatus.ApplicationPeakMemoryUsage; // 單位:位元組             lblMsg.Text += Environment.NewLine;                lblMsg.Text += "硬體版本:" + DeviceStatus.DeviceHardwareVersion;             lblMsg.Text += Environment.NewLine;                lblMsg.Text += "韌體版本:" + DeviceStatus.DeviceFirmwareVersion;             lblMsg.Text += Environment.NewLine;                lblMsg.Text += "裝置是否包含物理鍵盤:" + DeviceStatus.IsKeyboardPresent;             lblMsg.Text += Environment.NewLine;                lblMsg.Text += "物理鍵盤是否正在使用:" + DeviceStatus.IsKeyboardDeployed;             lblMsg.Text += Environment.NewLine;                /*              * Microsoft.Phone.Info.PowerSource 枚舉 - 供電方式              *     Battery - 電池              *     External - 外接電源              */            lblMsg.Text += "供電方式:" + DeviceStatus.PowerSource;              lblMsg.Text += Environment.NewLine;                lblMsg.Text += "是否支援多解析度編碼視頻的Smooth Streaming:" + MediaCapabilities.IsMultiResolutionVideoSupported;             lblMsg.Text += Environment.NewLine;                lblMsg.Text += "裝置標識:" + GetDeviceUniqueId();                            // 當物理鍵盤的使用狀態(使用或關閉)發生改變時所觸發的事件             DeviceStatus.KeyboardDeployedChanged += new EventHandler(DeviceStatus_KeyboardDeployedChanged);                // 當裝置的供電方式(電池或外接電源)發生改變時所觸發的事件             DeviceStatus.PowerSourceChanged += new EventHandler(DeviceStatus_PowerSourceChanged);         }            void DeviceStatus_PowerSourceChanged(object sender, EventArgs e)         {             MessageBox.Show("供電方式:" + DeviceStatus.PowerSource);         }            void DeviceStatus_KeyboardDeployedChanged(object sender, EventArgs e)         {             MessageBox.Show("物理鍵盤是否正在使用:" + DeviceStatus.IsKeyboardDeployed);         }            /// <summary>         /// 擷取裝置的唯一ID         /// </summary>         private string GetDeviceUniqueId()         {             string result = "";             object uniqueId;             /*              * DeviceExtendedProperties.TryGetValue() - 用於擷取裝置的唯一ID              */            if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId))             {                 result = ByteToHexStr((byte[])uniqueId);                    if (result != null && result.Length == 40)                     result = result.Insert(8, "-").Insert(17, "-").Insert(26, "-").Insert(35, "-");             }                return result;         }            /// <summary>         /// 將一個位元組數群組轉換為十六進位字串         /// </summary>         private string ByteToHexStr(byte[] bytes)         {             string returnStr = "";             if (bytes != null)             {                 for (int i = 0; i < bytes.Length; i++)                 {                     returnStr += bytes[i].ToString("X2");                 }             }             return returnStr;         }     } }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.