Flashlight
Tip
This article covers Uno-specific information for Flashlight. For a full description of the feature and instructions on using it, see Lamp Class.
LampAPI allows you to turn the phone's camera flashlight on and off
Supported features
| Feature | Windows | Android | iOS | Web (WASM) | macOS | Linux (Skia) | Win 7 (Skia) |
|---|---|---|---|---|---|---|---|
GetDefaultAsync |
✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
IsEnabled |
✔ | ✔ | ✔ | ✖ | ✖ | ✖ | ✖ |
BrightnessLevel |
✔ | ✔ | ✔ | ✖ | ✖ | ✖ | ✖ |
Using Lamp with Uno
- The
GetDefaultAsyncmethod is implemented on all targets and will returnnullwhereLampis not supported. - Make sure to call
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 theLampneeds to be disposed of as well. - On iOS, in case the device supports the torch,
BrightnessLevelis fully supported. In case the device has only flash, any non-zeroBrightnessLevelwill result in the full brightness of the flashlight. - On Android, flashlight brightness cannot be controlled, hence any non-zero
BrightnessLevelresults in the full brightness of the flashlight.
Platform-specific requirements
Android
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" />
Example
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.
}