Windows Phone 7 obtains user information and device information

Source: Internet
Author: User

In Windows Phone 7, how does one obtain user information and device information? You only need to useUserextendedpropertiesClass andDeviceextendedpropertiesThe corresponding member functions of the class. How do I perform this operation? See the text.

Obtain user information

UseUserextendedpropertiesClassGetvalueAndTrygetvalueMethod. Currently, the input parameters of both functions only support "anid ".

The getvalue usage is as follows:

String anid = userextendedproperties. getvalue ("anid") as string; string anonymoususerid = anid. substring (2, 32 );

Trygetvalue usage:

Object anid = new object (); string anonymoususerid = ""; if (userextendedproperties. trygetvalue ("anid", out anid) {anonymoususerid = anid as string; anonymoususerid = anonymoususerid. substring (2, 32 );}

Note that if your WP7 mobile phone is not bound with a live ID,GetvalueThe returned string is null,TrygetvalueThe returned object is also null. Therefore, pay attention to the non-null judgment on the returned strings and objects in the project.

Get device information

Similar to getting user information, useDeviceextendedpropertiesClassGetvalueAndTrygetvalueMethod. The usage of these two methods is the same as that above. The difference is the input parameter. Windows Phone 7 can obtain the following device information:

Attribute name Value Type Description Additional instructions

Devicemanufacturer

String
(Maximum length: 256)
The manufacturer of the device. The string is not in the standard format. Microsoft recommends that mobile phones produced by the same manufacturer use the same string, but this is not mandatory. Note that this value may also be null
Devicename String
(Maximum length: 256)
Device Name. The string is not in the standard format. Note that this value may also be null

Deviceuniqueid

Byte array with a length of 20 The unique identifier of the device. This value is unique, even if the system is upgraded. Note: Do not use this value to identify the user, because the user may change the mobile phone and the same mobile phone may be used by different users.
Devicefirmwareversion A string The firmware version of the current device. If a new firmware version is installed, the value increases. Note that this value may also be null

Devicehardwareversion

A string The hardware version of the current device. Note that this value may also be null

Devicetotalmemory

Long Integer Physical memory size of the device (unit: byte) This value is usually slightly smaller than the actual Ram size, so you can use it to determine whether Ram is sufficient.

Applicationcurrentmemoryusage

Long Integer Current ApplicationProgramMemory Used (unit: byte) You can use it to observe the memory consumption of the current application.

Applicationpeakmemoryusage

Long Integer Peak memory usage of the current application (unit: byte) You can use it to observe the maximum memory usage of the current application.

Let's take a look at how to get the device vendor:

String strdevicemanufacturer = deviceextendedproperties. getvalue ("devicemanufacturer"). tostring ();

 

All other device information is obtained in the same way as the device manufacturer. You can change the getvalue or trygetvalue parameter.

One difference is deviceuniqueid. Sometimes we need to save a string to identify the uniqueness. It is a little troublesome to use the byte array. Here I traverse the array and convert it to a string with a length of 60,CodeAs follows:

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 ;}

 

On the demo interface, I only placed a few buttons and textblocks to obtain device information. Many of them are the same, and they are not listed. I will cut a picture for your reference:

It is the result of running on the simulator and cannot be bound to the liveid. Therefore, the user information cannot be obtained and it is null. All others are normal.

I can obtain relevant information for tests on a real machine. :)

For ease of use, I encapsulated the code for getting user and device information into a class, which is a public static method and can be used directly.

Download demo

if you find any problems, please inform me in time. Thank you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.