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

在我们写程序的时候,经常需要知道谁在使用这个程序或者说是程序运行在什么样的手机上。相比之前使用.NET CF来开发Windows Mobile系统上的应用程序来说,Windows Phone 7中提供的API就方便多了。

要获取用户或者Windows Phone 7的信息,首先需要在程序的WMAppManifest.xml中声明如下段落:

1. <Capability Name=“ID_CAP_IDENTITY_DEVICE“/>
2. <Capability Name=“ID_CAP_IDENTITY_USER“/>

 然后我们可以通过Microsoft.Phone.Info命名空间下的两个类“UserExtendedProperties”和 “DeviceExtendedProperties”来分别获取用户和设备的一些信息。这两个类里面都只有两个静态方法“GetValue” 和”TryGetValue”。你只需要传入想要查找的属性值就可以。

  目前来说,UserExtendedProperties里面只能查找到”ANID”这个值,它是将当前系统中的用户身份进行了某些运算之后得到的一个32位的字符串。同时,在模拟器上,或者在真实设备上如果没有绑定Windows Live ID的话,也获取不到任何数据。

  而对于DeviceExtendedProperties,可以获取的信息就相对多一些,例如设备的厂商,型号等等。而且也包含当前程序占用/峰值内存。

string anid = UserExtendedProperties.GetValue("ANID") as string;
System.Diagnostics.Debug.WriteLine("AnID: " + anid);
string result = string.Empty;
result = result + "Manufacturer:"+ DeviceExtendedProperties.GetValue("DeviceManufacturer").ToString() + System.Environment.NewLine;
result = result + "DeviceName:"+ DeviceExtendedProperties.GetValue("DeviceName").ToString() + System.Environment.NewLine;
result = result + "DeviceUniqueId:"+ DeviceExtendedProperties.GetValue("DeviceUniqueId") + System.Environment.NewLine;
result = result + "DeviceFirmwareVersion:"+ DeviceExtendedProperties.GetValue("DeviceFirmwareVersion").ToString() + System.Environment.NewLine;
result = result + "DeviceHardwareVersion:"+ DeviceExtendedProperties.GetValue("DeviceHardwareVersion").ToString() + System.Environment.NewLine;
result = result + "DeviceTotalMemory:"+ DeviceExtendedProperties.GetValue("DeviceTotalMemory").ToString() + System.Environment.NewLine;
result = result + "ApplicationCurrentMemoryUsage:" + DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage").ToString() + System.Environment.NewLine;
result = result + "ApplicationPeakMemoryUsage:"+ DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage").ToString();
System.Diagnostics.Debug.WriteLine(result);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值