Camera UI features for mobile devices

This article show you how to take advantage of special camera UI features that are only present on mobile devices.

Add the mobile extension to your project

To use these features, you must add a reference to the Microsoft Mobile Extension SDK for Universal App Platform to your project.

To add a reference to the mobile extension SDK for hardware camera button support

  1. In Solution Explorer, right-click References and select Add Reference.

  2. Expand the Windows Universal node and select Extensions.

  3. Select the Microsoft Mobile Extension SDK for Universal App Platform check box.

Hide the status bar

Mobile devices have a StatusBar control that provides the user with status information about the device. This control takes up space on the screen that can interfere with the media capture UI. You can hide the status bar by calling HideAsync, but you must make this call from within a conditional block where you use the ApiInformation.IsTypePresent method to determine if the API is available. This method will only return true on mobile devices that support the status bar. You should hide the status bar when your app launches or when you begin previewing from the camera.

// Hide the status bar
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
{
    await Windows.UI.ViewManagement.StatusBar.GetForCurrentView().HideAsync();
}

When your app is shutting down or when the user navigates away from the media capture page of your app, you can make the control visible again.

// Show the status bar
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
{
    await Windows.UI.ViewManagement.StatusBar.GetForCurrentView().ShowAsync();
}

Use the hardware camera button

Some mobile devices have a dedicated hardware camera button that some users prefer over an on-screen control. To be notified when the hardware camera button is pressed, register a handler for the HardwareButtons.CameraPressed event. Because this API is available on mobile devices only, you must again use the IsTypePresent to make sure the API is supported on the current device before attempting to access it.

using Windows.Phone.UI.Input;
if (ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
{
    HardwareButtons.CameraPressed += HardwareButtons_CameraPressed;
}

In the handler for the CameraPressed event, you can initiate a photo capture.

private async void HardwareButtons_CameraPressed(object sender, CameraEventArgs e)
{
    await TakePhotoAsync();
}

When your app is shutting down or the user moves away from the media capture page of your app, unregister the hardware button handler.

if (ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
{
    HardwareButtons.CameraPressed -= HardwareButtons_CameraPressed;
}