Switch the Flashlight / Torch of your device.
npm install @capgo/capacitor-flash
npx cap sync
Works out of the box
- Declare permissions in your app's
AndroidManifest.xml
file
<!-- Permissions: Allows access to flashlight -->
<uses-permission android:name="android.permission.CAMERA" android:maxSdkVersion="23" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<!-- Actual Hardware Features Used-->
<uses-feature android:name="android.hardware.camera.flash" android:required="true" />
isAvailable() => Promise<{ value: boolean; }>
Checks if flashlight is available
Returns: Promise<{ value: boolean; }>
switchOn(options: { intensity?: number; }) => Promise<void>
Turns the flashlight on
Param | Type |
---|---|
options |
{ intensity?: number; } |
switchOff() => Promise<void>
Turns the flashlight off
isSwitchedOn() => Promise<{ value: boolean; }>
Checks if the flashlight is turned on or off
Returns: Promise<{ value: boolean; }>
toggle() => Promise<{ value: boolean; }>
Toggle the flashlight
Returns: Promise<{ value: boolean; }>