📜 ⬆️ ⬇️

How to programmatically find out the hardware characteristics of the device on Windows Phone 7.1. Mango

Two days ago I downloaded a new development package for Windows Phone 7.1 (Mango) and began to explore new features. Found that the DeviceExtendedProperties class is now obsolete and not recommended for use (deprecated). It was replaced by a more clear and convenient class DeviceStatus . Here we will talk about it.

The new DeviceStatus class belongs to the same Microsoft.Phone.Info namespace as the outdated DeviceExtendedProperties. It is very convenient that you do not need to memorize new property names. They remained the same - just changed the syntax. For example, the old version was:
 textBlockGetManufacture.Text = DeviceExtendedProperties.GetValue ("DeviceManufacturer"). ToString ();

It became:
 textBlockGetManufacture.Text = Microsoft.Phone.Info.DeviceStatus.DeviceManufacturer;


In addition, new useful properties related to the keyboard and power have been added to the DeviceStatus class.
To see all the changes, I took my old example as a basis for the hardware characteristics of the Windows Phone 7 device and began to rework it.
First, I launched an old project written for Windows Phone 7. Then in the Project menu I selected Properties and in the window that opens I selected Windows Phone 7.1 from the Target Windows Phone Version list

Now it remains to replace the outdated properties with new ones:

public MainPage() { InitializeComponent(); timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 10); timer.Tick += new EventHandler(timer_Tick); } DispatcherTimer timer; private void butGetInfo_Click(object sender, RoutedEventArgs e) { //  //  // textBlockGetManufacture.Text = DeviceExtendedProperties.GetValue("DeviceManufacturer").ToString(); //   Windows Phone 7.1 Mango textBlockGetManufacture.Text = Microsoft.Phone.Info.DeviceStatus.DeviceManufacturer; //   //  // textBlockGetName.Text = DeviceExtendedProperties.GetValue("DeviceName").ToString(); //   Windows Phone 7.1 Mango textBlockGetName.Text = Microsoft.Phone.Info.DeviceStatus.DeviceName; //    byte[] id = (byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId"); textBlockGetID.Text = BitConverter.ToString(id); //   //  // textBlockGetFirmware.Text = DeviceExtendedProperties.GetValue("DeviceFirmwareVersion").ToString(); //   Windows Phone 7.1 Mango textBlockGetFirmware.Text = Microsoft.Phone.Info.DeviceStatus.DeviceFirmwareVersion; //   //  // textBlockGetHardware.Text = DeviceExtendedProperties.GetValue("DeviceHardwareVersion").ToString(); //   Windows Phone 7.1 Mango textBlockGetHardware.Text = Microsoft.Phone.Info.DeviceStatus.DeviceHardwareVersion; //     //  //var maxmem = (long)DeviceExtendedProperties.GetValue("DeviceTotalMemory"); // maxmem /= 1024 * 1024; //textBlockGetTotalMemory.Text = maxmem.ToString(); // Windows 7.1. Mango var totalmem = Microsoft.Phone.Info.DeviceStatus.DeviceTotalMemory; totalmem /= 1024 * 1024; textBlockGetTotalMemory.Text = totalmem.ToString(); //   Windows 7.1 Mango //    textBlockGetKeyboardDeploy.Text = Microsoft.Phone.Info.DeviceStatus.IsKeyboardDeployed.ToString(); //     textBlockGetPresentKeyboard.Text = Microsoft.Phone.Info.DeviceStatus.IsKeyboardPresent.ToString(); //   textBlockGetPowerSource.Text = Microsoft.Phone.Info.DeviceStatus.PowerSource.ToString(); } private void buttonMemory_Click(object sender, RoutedEventArgs e) { timer.Start(); } void timer_Tick(object sender, EventArgs e) { try { //  // textBlockGetCurrentMemory.Text = DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage").ToString(); // textBlockGetPeakMemory.Text = DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage").ToString(); // Windows 7.1. Mango textBlockGetCurrentMemory.Text = Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage.ToString(); textBlockGetPeakMemory.Text = Microsoft.Phone.Info.DeviceStatus.ApplicationPeakMemoryUsage.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } 

')


For convenience, I have divided the logic of the code into two parts. In the first part, I display the values ​​of the constant properties: the name of the manufacturer, the firmware number and the total amount of memory. It is worth noting that in the obsolete DeviceExtendedProperties class, it was possible to obtain a unique device number through the DeviceUniqueId property. In the new class there was no analogue. I also noticed that earlier the value of 371 was returned for the total memory, and in Mango it became 435 MB.

New Mango Properties


Now a few words about the updates. There is a new property IsKeyboardPresent , which determines the presence of a hardware keyboard on the device. The emulator always returns True, as the emulator sees your desktop keyboard. I remember that the Windows Mobile emulator had the same behavior. You can try to pull out the keyboard wire from the system unit and look at the result, but I decided to leave this issue to you.
There is also a new property IsKeyboardDeployed , which works in conjunction with the previous property. With it, you can find out whether the user has pushed the keyboard to work or not. Before using this property, it makes sense to verify the presence of a hardware keyboard using IsKeyboardPresent.
Another useful feature is PowerSources . With it, you can find out whether the device works from a battery or from an external source (electrical outlet or connected to a computer).

Android, ay


In one of my latest publications on Habré, I suggested that programmers who write applications for Android write an analog of the program described. I propose to continue the tradition and tell you how to get the hardware characteristics of the phone on Android.
I would also be happy to answer from iPhone developers.

Source: https://habr.com/ru/post/120154/


All Articles