Flashlight

This plugin allows you switch the flaslight / torch of your device on or off.
Icenium1.01
platforms: ios,android,wp8
$ cordova plugin add nl.x-services.plugins.flashlight

PhoneGap Flashlight / Torch plugin

by Eddy Verbruggen for iOS and Android, PhoneGap 3+

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

1. Description

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

  • Works on Android, probably as far back as version 2.1.
  • Works on iOS 5.0+, maybe even lower.
  • 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

Automatically (CLI / Plugman)

Flashlight is compatible with Cordova Plugman, compatible with PhoneGap 3.0 CLI, here's how it works with the CLI:

$ cordova plugin add https://github.com/EddyVerbruggen/Flashlight-PhoneGap-Plugin.git
$ cordova prepare

Then reference Flashlight.js in index.html, after cordova.js/phonegap.js. Mind the path:

<script type="text/javascript" src="js/plugins/Flashlight.js"></script>

Manually

1. Add the following xml to your config.xml in the root directory of your www folder:

<!-- for iOS -->
<feature name="Flashlight">
  <param name="ios-package" value="Flashlight" />
</feature>
<!-- for Android -->
<feature name="Flashlight">
  <param name="android-package" value="nl.xservices.plugins.Flashlight" />
</feature>

2. For Android, add the following xml to your AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA"/>

3. Grab a copy of Flashlight.js, add it to your project and reference it in index.html:

<script type="text/javascript" src="js/plugins/Flashlight.js"></script>

4. Download the source files for iOS and/or Android and copy them to your project.

iOS: Copy Flashlight.h and Flashlight.h to platforms/ios/<ProjectName>/Plugins

Android: Copy Flashlight.java to platforms/android/src/nl/xservices/plugins (create the folders)

PhoneGap Build

Flashlight works with PhoneGap build too! Compatible with PhoneGap 3.0.0 and up. You can implement the plugin with these simple steps.

1. Add the following xml to your config.xml to always use the latest version of this plugin:

<gap:plugin name="nl.x-services.plugins.flashlight" />

or to use this exact version:

<gap:plugin name="nl.x-services.plugins.flashlight" version="1.0" />

2. Reference the JavaScript code in your index.html:

<!-- below <script src="phonegap.js"></script> -->
<script src="js/plugins/Flashlight.js"></script>

3. Usage

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

    // switch on
    window.plugins.flashlight.switchOn(); // success/error callbacks may be passed

    // 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

window.plugins.flashlight.toggle(); // success/error callbacks may be passed

4. CREDITS

5. License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Bitdeli Badge