Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
cordova-plugin-flashlight
Advanced tools
This plugin allows you switch the Flashlight / Torch of your device on or off.
by Eddy Verbruggen for iOS, Android and WP8
This plugin allows you to switch the flashlight / torch of the device on and off.
Latest stable version from npm:
$ cordova plugin add cordova-plugin-flashlight
Bleeding edge version from Github:
$ cordova plugin add https://github.com/EddyVerbruggen/Flashlight-PhoneGap-Plugin
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" />
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
window.plugins.flashlight.switchOn(
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
window.plugins.flashlight.toggle(
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() {
navigator.app.exitApp();
}
FAQs
This plugin allows you switch the Flashlight / Torch of your device on or off.
We found that cordova-plugin-flashlight demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.