Skip to content

Instantly share code, notes, and snippets.

@beeradmoore
Created May 28, 2014 10:26
Show Gist options
  • Save beeradmoore/bf43c95e81686e36c7a1 to your computer and use it in GitHub Desktop.
Save beeradmoore/bf43c95e81686e36c7a1 to your computer and use it in GitHub Desktop.
General use function to detect flash with Xamarin.Android
public bool HasFlash()
{
if (_camera == null)
{
return false;
}
bool hasFlash = MyMainActivity.PackageManager.HasSystemFeature(Android.Content.PM.PackageManager.FeatureCameraFlash);
if (hasFlash)
return true;
Camera.Parameters parameters = _camera.GetParameters();
if (parameters.FlashMode == null)
{
return false;
}
List<string> supportedFlashModes = parameters.SupportedFlashModes.ToList<string>();
if (supportedFlashModes == null || supportedFlashModes.Count == 0 || (supportedFlashModes.Count == 1 && supportedFlashModes[0].Equals(Camera.Parameters.FlashModeOff)))
{
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment