【window phone 7】如何获取用户和手机的信息
2011-09-20 14:46
651 查看
在我们写程序的时候,经常需要知道谁在使用这个程序或者说是程序运行在什么样的手机上。相比之前使用.NET CF来开发Windows Mobile系统上的应用程序来说,Windows Phone 7中提供的API就方便多了。
要获取用户或者Windows Phone 7的信息,首先需要在程序的WMAppManifest.xml中声明如下段落:
Code Snippet
<Capability Name=“ID_CAP_IDENTITY_DEVICE“/>
<Capability Name=“ID_CAP_IDENTITY_USER“/>
然后我们可以通过Microsoft.Phone.Info命名空间下的两个类“UserExtendedProperties”和“DeviceExtendedProperties”来分别获取用户和设备的一些信息。这两个类里面都只有两个静态方法“GetValue”和”TryGetValue”。你只需要传入想要查找的属性值就可以。
目前来说,UserExtendedProperties里面只能查找到”ANID”这个值,它是将当前系统中的用户身份进行了某些运算之后得到的一个32位的字符串。同时,在模拟器上,或者在真实设备上如果没有绑定Windows Live ID的话,也获取不到任何数据。
而对于DeviceExtendedProperties,可以获取的信息就相对多一些,例如设备的厂商,型号等等。而且也包含当前程序占用/峰值内存。
编写Demo代码如下:
string anid = UserExtendedProperties.GetValue(“ANID”) as string;
System.Diagnostics.Debug.WriteLine(“ANID:”+ anid);
string result = “AnonymousUserId: “ + anid.Substring(2, 32) + System.Environment.NewLine;
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);
this.textBlock1.Text = result;
意的是,代码中所获取的DeviceUniqueId它只是一个Byte[],所以这里的ToString()方法只能获取到它的类型名。
最后得到结果如下:
ANID:A=FB338361532E5A2A295F9834FFFFFFFF&E=a63&W=1
AnonymousUserId: FB338361532E5A2A295F9834FFFFFFFF
Manufacturer:LG
DeviceName:GW910
DeviceUniqueId:System.Byte[]
DeviceFirmwareVersion:0.8.2.3
DeviceHardwareVersion:1.1.0.0
DeviceTotalMemory:236335104
ApplicationCurrentMemoryUsage:8744960
ApplicationPeakMemoryUsage:8744960
要获取用户或者Windows Phone 7的信息,首先需要在程序的WMAppManifest.xml中声明如下段落:
Code Snippet
<Capability Name=“ID_CAP_IDENTITY_DEVICE“/>
<Capability Name=“ID_CAP_IDENTITY_USER“/>
然后我们可以通过Microsoft.Phone.Info命名空间下的两个类“UserExtendedProperties”和“DeviceExtendedProperties”来分别获取用户和设备的一些信息。这两个类里面都只有两个静态方法“GetValue”和”TryGetValue”。你只需要传入想要查找的属性值就可以。
目前来说,UserExtendedProperties里面只能查找到”ANID”这个值,它是将当前系统中的用户身份进行了某些运算之后得到的一个32位的字符串。同时,在模拟器上,或者在真实设备上如果没有绑定Windows Live ID的话,也获取不到任何数据。
而对于DeviceExtendedProperties,可以获取的信息就相对多一些,例如设备的厂商,型号等等。而且也包含当前程序占用/峰值内存。
编写Demo代码如下:
string anid = UserExtendedProperties.GetValue(“ANID”) as string;
System.Diagnostics.Debug.WriteLine(“ANID:”+ anid);
string result = “AnonymousUserId: “ + anid.Substring(2, 32) + System.Environment.NewLine;
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);
this.textBlock1.Text = result;
意的是,代码中所获取的DeviceUniqueId它只是一个Byte[],所以这里的ToString()方法只能获取到它的类型名。
最后得到结果如下:
ANID:A=FB338361532E5A2A295F9834FFFFFFFF&E=a63&W=1
AnonymousUserId: FB338361532E5A2A295F9834FFFFFFFF
Manufacturer:LG
DeviceName:GW910
DeviceUniqueId:System.Byte[]
DeviceFirmwareVersion:0.8.2.3
DeviceHardwareVersion:1.1.0.0
DeviceTotalMemory:236335104
ApplicationCurrentMemoryUsage:8744960
ApplicationPeakMemoryUsage:8744960
相关文章推荐
- WP7 Dev 101 【4】 如何获取用户和手机的信息
- WP7 如何获取用户和手机的信息
- 如何获取用户和手机的信息
- WP如何获取用户和手机信息
- WP7 Dev 101 【4】 如何获取用户和手机的信息
- Windows Phone 7 如何获取用户和手机的信息
- 如何获取手机用户的位置信息
- Android 如何获取手机总内存和可用内存等信息
- 如何获取WordPress当前用户信息
- Android如何判断当前手机是否正在播放音乐,并获取到正在播放的音乐的信息
- [置顶] java微信开发-之如何获取openid 和用户信息
- unity如何获取安卓手机的时间电量网络信息
- Navigator 对象、如何获取用户的浏览器信息(UA)、常见浏览器的 User-Agent
- Python脚本如何获取当前环节和用户等信息
- 第七篇 :微信公众平台开发实战Java版之如何获取微信用户基本信息
- android学习笔记--如何获取手机联系人的信息
- 小程序使用wx.chooseAddress获取用户手机号码,微信chooseAddress接口获取收货信息
- 展会企业邮件群发如何获取用户信息
- 如何获取WAP用户的手机号码(收集)
- 第八篇 :微信公众平台开发实战Java版之如何网页授权获取用户基本信息