Skip to content
🔦 Cordova plugin for using the torch / flashlight of your device
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Torch intensity control on iOS Sep 17, 2016
www Torch intensity control on iOS Sep 17, 2016
.gitignore initial import Nov 10, 2013
LICENSE Moving to npm Oct 21, 2015

PhoneGap Flashlight / Torch plugin

by Eddy Verbruggen for iOS, Android and WP8

  1. Description
  2. Installation 2. Automatically (CLI / Plugman) 2. Manually 2. PhoneGap Build
  3. Usage
  4. Credits

1. Description

This plugin allows you to switch the flashlight / torch of the device on and off.

  • Works on iOS 5+
  • Works on Android 2+
  • Android 6+ runtime permissions are handled automatically
  • Works on WP8
  • Depends on capabilities of the device, so you can test it with an API call
  • Compatible with Cordova Plugman
  • Pending review at PhoneGap Build

2. Installation

Latest stable version from npm:

$ cordova plugin add cordova-plugin-flashlight

Bleeding edge version from Github:

$ cordova plugin add

PhoneGap Build

Flashlight works with PhoneGap build too! Compatible with PhoneGap 3.0.0 and up. Just add the following xml to your config.xml to always use the latest version of this plugin:

<gap:plugin name="cordova-plugin-flashlight" source="npm" />

3. Usage

Since version 3.2.0 of this plugin you can pass in an intensity property which needs to be anywhere between 0.0 and 1.0. Only on iOS this will affect the brightness of the torch.

window.plugins.flashlight.available(function(isAvailable) {
  if (isAvailable) {

    // switch on
      function() {}, // optional success callback
      function() {}, // optional error callback
      {intensity: 0.3} // optional as well

    // switch off after 3 seconds
    setTimeout(function() {
      window.plugins.flashlight.switchOff(); // success/error callbacks may be passed
    }, 3000);

  } else {
    alert("Flashlight not available on this device");

As an alternative to switchOn and switchOff, you can use the toggle function

  function() {}, // optional success callback
  function() {}, // optional error callback
  {intensity: 0.3} // optional as well, used on iOS when switching on

To know if the flashlight is on or off you can call isSwitchedOn

window.plugins.flashlight.isSwitchedOn(); // returns true/false

A hint for Android developers: you'll want to make sure the torch is switched off when the app is exited via the backbutton. Otherwise, the camera may be locked so it can't be used by other apps:

document.addEventListener("backbutton", function() {
  // pass exitApp as callbacks to the switchOff method
  window.plugins.flashlight.switchOff(exitApp, exitApp);
}, false);

function exitApp() {;


You can’t perform that action at this time.