Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 05:32, 23 October 2012 by Vaishali Rawat (Talk | contribs)

How to detect camera availability in Windows Phone

From Wiki
Jump to: navigation, search

This article explains how to port the camera detection code from Android to Windows Phone 7.

WP Metro Icon Multimedia.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Tested with
SDK: Windows Phone 7.1
Platform(s): Windows Phone 7.5
Windows Phone 8
Windows Phone 7.5
Created: Vaishali Rawat (19 Oct 2012)
Last edited: Vaishali Rawat (23 Oct 2012)



Detecting whether the camera is available on the device or not can be helpful in applications which require to launch camera. If we try to open camera without checking its existence , chances are there that the app may crash. So, its always better to determine in advance what kind of camera (primary, secondary or both) are available on the device.

Detecting camera existence in Android

In Android, we use PackageManager class to determine whether the phone supports camera or not. The PackageManager class provides a function hasSystemFeature to determine whether a particular feature is available in the device or not. This function accepts a string type parameter stating about the feature whose information we need. To determine camera existence, the parameter string we'll use is FEATURE_CAMERA.

The code to detect camera existence in Android:

Boolean isAvailable =  packagemanager.hasSystemFeature(PackageManager.FEATURE_CAMERA);

Detecting camera existence in Windows Phone 7

To detect camera existence in device, we use PhotoCamera API. As in Android, the PhotoCamera API provides a function IsCameraTypeSupported which accepts a string type variable stating the camera type.

The code to detect camera existence in Windows Phone 7:

  • First we create an instance of PhotoCamera
private PhotoCamera _Camera;
  • Next, we invoke the DETECT_CAMERA() method
 public void DETECT_CAMERA()
if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) && PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
MessageBox.Show("Both Primary and Secondary Camera's are available.");
else if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing))
MessageBox.Show("Only Secondary Camera is available.");
else if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
MessageBox.Show("Only Primary Camera is available.");
MessageBox.Show("No Camera available on this Device.");


Now we have successfully ported the code of camera detection from Android to Windows Phone 7.

85 page views in the last 30 days.