doc/articles/features/flashlight.md
[!TIP] This article covers Uno-specific information for Flashlight. For a full description of the feature and instructions on using it, see Lamp Class.
Lamp API allows you to turn the phone's camera flashlight on and off| Feature | Windows | Android | iOS | Web (WASM) | macOS | Linux (Skia) | Win 7 (Skia) |
|---|---|---|---|---|---|---|---|
GetDefaultAsync | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
IsEnabled | ✔ | ✔ | ✔ | ✖ | ✖ | ✖ | ✖ |
BrightnessLevel | ✔ | ✔ | ✔ | ✖ | ✖ | ✖ | ✖ |
Lamp with UnoGetDefaultAsync method is implemented on all targets and will return null where Lamp is not supported.Lamp.Dispose() after use, as implementation on both iOS and Android uses unmanaged resources, and not disposing of them could cause a memory leak. This is in line with WinUI, where the Lamp needs to be disposed of as well.BrightnessLevel is fully supported. In case the device has only flash, any non-zero BrightnessLevel will result in the full brightness of the flashlight.BrightnessLevel results in the full brightness of the flashlight.For Android, there are two permissions you must configure before using this API in your project. To do that, add the following to AndroidManifest.xml:
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.CAMERA" />
if (await Lamp.GetDefaultAsync() is Lamp lamp)
{
lamp.IsEnabled = true; // Turn on the flashlight.
lamp.BrightnessLevel = 0.5; // Set brightness of 50 %.
lamp.IsEnabled = false; // Turn off the flashlight.
lamp.Dispose(); // Stop using flashlight and clean up resources.
}