Using the camera
Making use of the camera allows the user to interact with the real world through the device. This can range from taking a photo and adding a message and effects all the way to providing an augmented reality experience.
How to do it...
If our app requires a photo, we can make use of the camera to record an image. However, we need to first ensure that there is a camera available on the device for us to use:
- If our app requires the camera and cannot function without it, we can enforce this by specifying that there must be a camera on the device in the features:
[assembly: UsesFeature(PackageManager.FeatureCamera)] [assembly: UsesFeature(PackageManager.FeatureCameraFront)]
- If the feature is not required, we can indicate that it is optional by adding the
Required
property to the[UsesFeature]
attribute:[assembly: UsesFeature(..., Required = false)]
- Then, we can check when the app starts if the feature is available and adjust functionality accordingly:
if (!PackageManager.HasSystemFeature...