Hello,
Welcome to our Microsoft Q&A platform!
Flashlight is not include in the Xamarin.GooglePlayServices.Vision
API, Google implemented those features (CameraSource.Builder) in native android CameraSource.Builder setFlashMode.
This feature request is opened like this thread: Support getCamera() instance in CameraSource.
Here is two ways to enable the flash mode.
Download this native android library from Google, binding this library. Here's a good article on how to get started: Binding a Java Library.
Using Reflection. You can get the Camera
Object from CameraSouce
and add the flash parameter then set the updated parameters to the camera. private void Button1_Click(object sender, System.EventArgs e)
//call it to open the Flash
setFlash(true);
public Android.Hardware.Camera getCameraObject(CameraSource _camSource)
Field[] cFields = _camSource.Class.GetDeclaredFields();
Android.Hardware.Camera _cam = null;
foreach (Field item in cFields)
if (item.Type.CanonicalName == "android.hardware.Camera")
Console.WriteLine("Camera");
item.Accessible = true;
_cam = (Android.Hardware.Camera)item.Get(_camSource);
catch (Exception e)
catch (Exception e)
return _cam;
bool isTorch;
public void setFlash(bool isEnable)
isTorch = !isEnable;
Android.Hardware.Camera _cam = getCameraObject(mCameraSource);
if (_cam == null) return;
var _pareMeters = _cam.GetParameters();
var _listOfSuppo = _cam.GetParameters().SupportedFlashModes;
_pareMeters.FlashMode = isTorch ? _listOfSuppo[0] : _listOfSuppo[3];
_cam.SetParameters(_pareMeters);
catch (Exception e)
And do not forget to add android.permission.FLASHLIGHT
permission in the AndroidManifest.xml
.
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.