capacitor-flash

Switch the Flashlight / Torch of your device.

Usage no npm install needed!

<script type="module">
  import capacitorFlash from 'https://cdn.skypack.dev/capacitor-flash';
</script>

README

capacitor-flash

Switch the Flashlight / Torch of your device.

Install

npm install capacitor-flash
npx cap sync

iOS

Works out of the box

Android

  1. 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" />

API

isAvailable()

isAvailable() => Promise<{ value: boolean; }>

Checks if flashlight is available

Returns: Promise<{ value: boolean; }>


switchOn(...)

switchOn(options: { intensity?: number; }) => Promise<void>

Turns the flashlight on

Param Type
options { intensity?: number; }

switchOff()

switchOff() => Promise<void>

Turns the flashlight off


isSwitchedOn()

isSwitchedOn() => Promise<{ value: boolean; }>

Checks if the flashlight is turned on or off

Returns: Promise<{ value: boolean; }>


toggle()

toggle() => Promise<{ value: boolean; }>

Toggle the flashlight

Returns: Promise<{ value: boolean; }>