Windows Phone 7 如何获取用户和手机的信息

转自:http://www.open-open.com/lib/view/open1326521794468.html

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Info;

namespace MicroBlogForWP7.Classes.Util
{
    public class UserDeviceInfo
    {
        /// <summary>
        /// 获取用户唯一标识
        /// </summary>
        /// <returns></returns>
        public static string GetUserID()
        { 
            object anid = new object();
            string anonymousUserId = "";
            if (UserExtendedProperties.TryGetValue("ANID", out anid))
            {
                if (null == anid)
                {
                    return string.Empty;
                }
                anonymousUserId = anid as string;
                anonymousUserId = anonymousUserId.Substring(2, 32);
            }
            return anonymousUserId;
        }


        /// <summary>
        /// 获取设备唯一标识
        /// </summary>
        /// <returns></returns>
        public static string GetDeviceUniqueId()
        {
            byte[] byteArray = DeviceExtendedProperties.GetValue("DeviceUniqueId") as byte[];
            string strTemp = "";
            string strDeviceUniqueID = "";
            foreach (byte b in byteArray)
            {
                strTemp = b.ToString();
                if (1 == strTemp.Length)
                {
                    strTemp = "00" + strTemp;
                }
                else if (2 == strTemp.Length)
                {
                    strTemp = "0" + strTemp;
                }
                strDeviceUniqueID += strTemp;
            }
            return strDeviceUniqueID;
        }


        /// <summary>
        /// 获取设备生产厂商
        /// </summary>
        /// <returns></returns>
        public static string GetDeviceManufacturer()
        {
            string strDeviceManufacturer = DeviceExtendedProperties.GetValue("DeviceManufacturer").ToString();
            return strDeviceManufacturer;
        }


        /// <summary>
        /// 获取当前应用程序使用的内存大小(单位是Byte)
        /// </summary>
        /// <returns></returns>
        public static string GetApplicationCurrentMemoryUsage()
        {
            string strDeviceManufacturer = DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage").ToString();
            return strDeviceManufacturer;
        }


        /// <summary>
        /// 获取设备名称
        /// </summary>
        /// <returns></returns>
        public static string GetDeviceName()
        {
            string strDeviceName = DeviceExtendedProperties.GetValue("DeviceName").ToString();
            return strDeviceName;
        }


        /// <summary>
        /// 获取设备固件版本
        /// </summary>
        /// <returns></returns>
        public static string GetDeviceFirmwareVersion()
        {
            string strDeviceFirmwareVersion = DeviceExtendedProperties.GetValue("DeviceFirmwareVersion").ToString();
            return strDeviceFirmwareVersion;
        }


        /// <summary>
        /// 获取设备硬件版本
        /// </summary>
        /// <returns></returns>
        public static string GetDeviceHardwareVersion()
        {
            string strDeviceHardwareVersion = DeviceExtendedProperties.GetValue("DeviceHardwareVersion").ToString();
            return strDeviceHardwareVersion;
        }


        /// <summary>
        /// 获取设备内存大小(单位是Byte)
        /// </summary>
        /// <returns></returns>
        public static string GetDeviceTotalMemory()
        {
            string strDeviceTotalMemory = DeviceExtendedProperties.GetValue("DeviceTotalMemory").ToString();
            return strDeviceTotalMemory;
        }


        /// <summary>
        /// 获取应用程序峰值内存大小(单位是Byte)
        /// </summary>
        /// <returns></returns>
        public static string GetApplicationPeakMemoryUsage()
        {
            string strApplicationPeakMemoryUsage = DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage").ToString();
            return strApplicationPeakMemoryUsage;
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值