Introduction
In this article you will learn how to determine the device status such as total memory of the device , the hardware version, Firmware Version, Memory usage, total memory, Manufacturer, device name and whether a physical keyboard has been deployed.
Follow the simple steps
Step 1: Create a Windows Phone 8 Application project.
Step 2: Make 12 TextBlocks in MainPage.xaml to display device status.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Name="CurrentMemoryUsage" Margin="20,0,0,0" FontSize="28" Text="" />
<TextBlock Name="MemoryUsageLimit" Margin="20,50,0,0" FontSize="28" Text="" /> <TextBlock Name="PeakMemoryUsage" Margin="20,100,0,0" FontSize="28" Text="" />
<TextBlock Name="FirmwareVersion" Margin="20,150,0,0" FontSize="28" Text="" />
<TextBlock Name="HardwareVersion" Margin="20,200,0,0" FontSize="28" Text="" />
<TextBlock Name="Manufacture" Margin="20,250,0,0" FontSize="28" \
Text="" />
<TextBlock Name="Name" Margin="20,300,0,0" FontSize="28" Text="" />
<TextBlock Name="TotalMemory" Margin="20,350,0,0" FontSize="28" Text="" />
<TextBlock Name="KeyBoardDeployed" Margin="20,400,0,0" FontSize="28"
Text="" />
Text="" />
<TextBlock Name="KeyBoardPresent" Margin="20,450,0,0" FontSize="28" Text="" />
<TextBlock Name="PowerSourcee" Margin="20,500,0,0" FontSize="28" Text="" />
<TextBlock Name="MultiResolutionVideoSupported" Margin="20,550,0,0" FontSize="28" Text="">
</Grid>
Step 3: Add the directive in Mainpage.xaml.cs
using Microsoft.Phone.Info;
Step 4: Now we will use static methods and properties of DeviceStatus class to find out different status of device.
After initialize component write following Code
CurrentMemoryUsage.Text = "Current Memory Usage:" + DeviceStatus.ApplicationCurrentMemoryUsage;MemoryUsageLimit.Text = "Memory Usage Limit: " + DeviceStatus.ApplicationMemoryUsageLimit;
PeakMemoryUsage.Text = "Peak Memory Usage: " + DeviceStatus.ApplicationPeakMemoryUsage;
FirmwareVersion.Text = "Firmware Version: " + DeviceStatus.DeviceFirmwareVersion;
HardwareVersion.Text = "Hardware Version: " + DeviceStatus.DeviceHardwareVersion;
Manufacture.Text = "Manufacturer: " + DeviceStatus.DeviceManufacturer;
Name.Text = "Name: " + DeviceStatus.DeviceName;TotalMemory.Text = "Total Memory: " + DeviceStatus.DeviceTotalMemory;
KeyBoardDeployed.Text = "IsKeyboardDeployed: " + DeviceStatus.IsKeyboardDeployed;
Step 5: Now Add the following code to Device_KeyboardDeployedChanged event and Device_PowerSourceChanged event.
</Grid>
Step 3: Add the directive in Mainpage.xaml.cs
using Microsoft.Phone.Info;
Step 4: Now we will use static methods and properties of DeviceStatus class to find out different status of device.
After initialize component write following Code
CurrentMemoryUsage.Text = "Current Memory Usage:" + DeviceStatus.ApplicationCurrentMemoryUsage;MemoryUsageLimit.Text = "Memory Usage Limit: " + DeviceStatus.ApplicationMemoryUsageLimit;
PeakMemoryUsage.Text = "Peak Memory Usage: " + DeviceStatus.ApplicationPeakMemoryUsage;
FirmwareVersion.Text = "Firmware Version: " + DeviceStatus.DeviceFirmwareVersion;
HardwareVersion.Text = "Hardware Version: " + DeviceStatus.DeviceHardwareVersion;
Manufacture.Text = "Manufacturer: " + DeviceStatus.DeviceManufacturer;
Name.Text = "Name: " + DeviceStatus.DeviceName;TotalMemory.Text = "Total Memory: " + DeviceStatus.DeviceTotalMemory;
KeyBoardDeployed.Text = "IsKeyboardDeployed: " + DeviceStatus.IsKeyboardDeployed;
KeyBoardPresent.Text = "IsKeyboardPresent: " + DeviceStatus.IsKeyboardPresent;
PowerSource.Text = "Power Source: " + PowerSource.ToString();
txtMultiResolutionVideoSupported.Text = "Multi Res Video Supported: " +MediaCapabilities.IsMultiResolutionVideoSupported;
//Create two event handlers for keyboard and Power source
DeviceStatus.KeyboardDeployedChanged += new EventHandler(Device_KeyboardDeployedChanged);
txtMultiResolutionVideoSupported.Text = "Multi Res Video Supported: " +MediaCapabilities.IsMultiResolutionVideoSupported;
//Create two event handlers for keyboard and Power source
DeviceStatus.KeyboardDeployedChanged += new EventHandler(Device_KeyboardDeployedChanged);
DeviceStatus.PowerSourceChanged += new EventHandler(Device_PowerSourceChanged);
Step 5: Now Add the following code to Device_KeyboardDeployedChanged event and Device_PowerSourceChanged event.
void Device_KeyboardDeployedChanged(object sender, EventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
KeyBoardDeployed.Text = DeviceStatus.IsKeyboardDeployed.ToString()
});
}
{
Dispatcher.BeginInvoke(() =>
{
KeyBoardDeployed.Text = DeviceStatus.IsKeyboardDeployed.ToString()
});
}
void Device_PowerSourceChanged(object sender, EventArgs e)
{
Dispatcher.BeginInvoke(()=>
{
txtPowerSource.Text = DeviceStatus.PowerSource.ToString();
});
}
{
Dispatcher.BeginInvoke(()=>
{
txtPowerSource.Text = DeviceStatus.PowerSource.ToString();
});
}
Step 3: Now run the application.

No comments:
Post a Comment