• [Windwos Phone 7] 获取设备相关信息


    摘要:这个是对Windwos Phone 7目前能拿得到的设备信息的封装。

    
    
         /// <summary>
        /// Get Device Information for Windows Phone
        /// </summary>
        public class DeviceInfo  
        {
            private static readonly int ANIDLength = 32;
            private static readonly int ANIDOffset = 2;
    
            #region - DeviceManufacturer -
    
            //NOTE:The name of the manufacturer of the device. 
            //There is no standard format for this string. 
            //It is recommended that the same value be used by every device from a manufacturer,
            //but this is not enforced. This value may be empty.
            public static string GetManufacturer()
            {
                string result = string.Empty;
                object manufacturer;
                if (DeviceExtendedProperties.TryGetValue("DeviceManufacturer", out manufacturer))
                    result = manufacturer.ToString();
    
                return result;
            }
    
            #endregion
    
            #region - DeviceName -
    
            //NOTE:The name of the device. 
            //There is no standard format for this string. 
            //This value may be empty.
            public static string GetDeviceName()
            {
                string result = string.Empty;
                object deviceName;
                if (DeviceExtendedProperties.TryGetValue("DeviceName", out deviceName))
                    result = deviceName.ToString();
    
                return result;
            }
    
            #endregion
    
            #region - DeviceUniqueId -
    
            //Note: to get a result requires ID_CAP_IDENTITY_DEVICE  
            // to be added to the capabilities of the WMAppManifest  
            // this will then warn users in marketplace  
            public static byte[] GetDeviceUniqueID()
            {
                byte[] result = null;
                object uniqueId;
                if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId))
                    result = (byte[])uniqueId;
    
                return result;
            }
    
            #endregion
    
            #region - DeviceFirmwareVersion -
    
            //NOTE: The firmware version running on the device. 
            //This is not the same as the OS version, which can be retrieved using System.Environment. 
            //It is recommended that the value be a string that can be parsed as a System.Version structure
            //and that it be incremented in a logical manner as newer firmware is installed, but this is not required. 
            //This value may be empty.
            public static Version GetDeviceFirmwareVersion()
            {
                string result = string.Empty;
                object deviceFirmwareVersion;
                if (DeviceExtendedProperties.TryGetValue("DeviceFirmwareVersion", out deviceFirmwareVersion))
                    result = deviceFirmwareVersion.ToString();
                Version version = new Version(deviceFirmwareVersion.ToString());
    
                return version;
            }
    
            #endregion
    
            #region - DeviceHardwareVersion -
    
            //NOTE:The hardware version running of the device. 
            //This is not the same as the OS version, which can be retrieved using System.Environment. 
            //It is recommended that the value be a string that can be parsed as a System.Version structure 
            //and that it be incremented in a logical manner as newer hardware is released, but this is not required. 
            //This value may be empty.
            public static Version GetDeviceHardwareVersion()
            {
                string result = string.Empty;
                object deviceFirmwareVersion;
                if (DeviceExtendedProperties.TryGetValue("DeviceHardwareVersion", out deviceFirmwareVersion))
                    result = deviceFirmwareVersion.ToString();
                Version version = new Version(deviceFirmwareVersion.ToString());
    
                return version;
            }
    
            #endregion
    
            #region - DeviceTotalMemory -
    
            //NOTE:The device’s physical RAM size in bytes. 
            //This value will be less than the actual amount of device memory, 
            //but can be used for determining memory consumption requirements.
            public static long GetDeviceTotalMemory()
            {
                long result = 0;
                object deviceTotalMemory;
                if (DeviceExtendedProperties.TryGetValue("DeviceTotalMemory", out deviceTotalMemory))
                    result = Convert.ToInt64(deviceTotalMemory);
    
                return result;
            }
    
            #endregion
    
            #region - ApplicationCurrentMemoryUsage  -
    
            //NOTE:The current application’s memory usage in bytes.
            public static long GetApplicationCurrentMemoryUsage()
            {
                long result = 0;
                object applicationCurrentMemoryUsage;
                if (DeviceExtendedProperties.TryGetValue("ApplicationCurrentMemoryUsage", out applicationCurrentMemoryUsage))
                    result = Convert.ToInt64(applicationCurrentMemoryUsage);
    
                return result;
            }
    
            #endregion
    
            #region - ApplicationPeakMemoryUsage -
    
            //NOTE:The current application’s peak memory usage in bytes.
            public static long GetApplicationPeakMemoryUsage()
            {
                long result = 0;
                object applicationPeakMemoryUsage;
                if (DeviceExtendedProperties.TryGetValue("ApplicationPeakMemoryUsage", out applicationPeakMemoryUsage))
                    result = Convert.ToInt64(applicationPeakMemoryUsage);
    
                return result;
            }
    
            #endregion
    
            #region - WindowsLiveId -
    
            // NOTE: to get a result requires ID_CAP_IDENTITY_USER  
            //  to be added to the capabilities of the WMAppManifest  
            // this will then warn users in marketplace  
            public static string GetWindowsLiveAnonymousID()
            {
                string result = string.Empty;
                object anid;
                if (UserExtendedProperties.TryGetValue("ANID", out anid))
                {
                    if (anid != null && anid.ToString().Length >= (ANIDLength + ANIDOffset))
                    {
                        result = anid.ToString().Substring(ANIDOffset, ANIDLength);
                    }
                }
    
                return result;
            }
    
            #endregion
        }

    详细设备信息可以看MSDN

  • 相关阅读:
    gulp安装
    ssh公钥自动登陆
    Laravel 依赖注入原理
    mac添加环境变量
    get和post的区别
    CPU进程与线程的关系和区别
    微信支付开发+{ping++}微信支付托管
    git学习笔记
    消除 activity 启动时白屏、黑屏问题
    转:android中APK开机自动运行
  • 原文地址:https://www.cnblogs.com/ssqjd/p/1875153.html
Copyright © 2020-2023  润新知