How to detect camera availability in Windows Phone
This article explains how to detect camera availability in Windows Phone 7 (and also briefly covers Android).
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, the app may crash. So, it is always better to determine in advance what kind of cameras (primary, secondary or both) are available on the device.
Detecting camera existence
To detect camera existence in device, we use PhotoCamera API. The PhotoCamera API provides a function IsCameraTypeSupported which accepts a string type variable stating the camera type.
The steps are:
- 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.");
You can download sample project code from this file Media:DetectingCamera.zip.