Flashlight Plugin

The flashlight plugin provides an api for controlling the hardware light found on most mobile devices. The light is typically mounted on the backside away from the display this plugin. Simulated flash using the display is not supported at this time. This plugin does not require other ezAR plugins to be present in order to operate. 


Installation

This plugin does not require additional ezAR plugins to be installed for it to operate. Thus install the plugin using your standard Cordova compliant tools.

   example - from commandline enter
     cordova plugin add path-to-plugins/com.ezartech.ezar.flashlight

Use-Cases & Snippets

The flashlight plugin has a very simple api and operation. 

Control the Device Light

This snippet illustrates the primary use for turning the device light on. Call ezar.initializeLight() before attempting to turn the device light on. The initialization step inspects the device to ensure that it has a light and that the app as permission to access it. After initialization you may then turn the light on and off as  you choose. 

ezar.initializeLight(
  function() {
    if (ezar.hasLight() {
      ezar.setLightOn();
    }
  },
  function(error) {
    alert("ezar light initialization failed");
  }); 

updated 20160620

Plugins
  Video Overlay
  Face Detection
  Snapshot
  Flashlight

 

Flashlight Plugin JavaScript API

Access the Flashlight JavaScript api through the global ezar.  You must initialize the flashlight plugin before invoking other flashlight functions. 

flashlight.js module

initializeLight(successCB,errorCB)

Asynchronously initialize the flashlight plugin. This function must be called before using other flashlight functions.

parameters

  • successCB callback function (optional) 
  • errorCB callback function (optional)
hasLight()

Determine if device has a light

return

  • bool, true if device has a light; false otherwise.
setLightOn(successCB,errorCB)

Asynchronously turn on the device light. Do nothing if light is already on.

Note: On Android devices, setting the light on will not take effect immediately when the VideoOverlay plugin is installed. The light will only turn on when video preview is started for the camera on the same side of the device as the light. This is due to the tight coupling between camera and light functionality of many Android devices. In such cases the light will automatically stop when the camera preview is stopped.

parameters

  • successCB callback function  (optional)
  • errorCB callback function with String error message parameter (optional)
setLightOff(successCB,errorCB)

Asynchronously turn off the device light. Do nothing if light is already off.

parameters

  • successCB callback function (optional) 
  • errorCB callback function with String error message parameter (optional)
isLightOn()

Determine if device light is on

return

  • bool, true if device has a light; false otherwise.