How to programmatically find out the hardware characteristics of a 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 opportunities. Found that the DeviceExtendedProperties class is now deprecated and not recommended (deprecated). It was replaced by a more understandable and convenient class DeviceStatus . We’ll talk about him.

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

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


    In addition, new useful keyboard and power related properties have been added to the DeviceStatus class.
    To see all the changes, I took as a basis my old example Hardware characteristics of the Windows Phone 7 device and began to process 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 in the Target Windows Phone Version list.

    Now it’s time to replace the obsolete properties with new ones:

    publicMainPage()
            {
                InitializeComponent();
                timer = new DispatcherTimer();
                timer.Interval = new TimeSpan(0, 0, 10);
                timer.Tick += new EventHandler(timer_Tick);
            }
            DispatcherTimer timer;
            privatevoidbutGetInfo_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. Mangovar 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();
            }
            privatevoidbuttonMemory_Click(object sender, RoutedEventArgs e)
            {
                timer.Start();
            }
            voidtimer_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 divided the code logic into two parts. In the first part, I display the values ​​of the constant properties: the name of the manufacturer, firmware number and total memory. It is worth noting that in the obsolete class DeviceExtendedProperties, it was possible to get a unique device number through the DeviceUniqueId property . There was no analogue in the new class. I also noticed that earlier, 371 was returned for shared memory, while in Mango it became 435 MB.

    New Mango Features


    Now a few words about the news. There is a new property IsKeyboardPresent , which determines the presence of a hardware keyboard on the device. True always returns on the emulator, since the emulator sees your desktop keyboard. I recall 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 the study of this issue to you.
    Also, a new IsKeyboardDeployed property has appeared , which works in conjunction with the previous property. With it, you can find out whether the user has advanced the keyboard for work or not. Before using this property, it makes sense to make sure you have a hardware keyboard using IsKeyboardPresent.
    Another useful feature is PowerSources . With it, you can find out whether the device is running on battery power or from an external source (electrical outlet or connected to a computer).

    Android, ay


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

    Also popular now: