Intel XDK and Cordova doesn’t provide any built in API to toggle flashlight on/off. We need to use Flashlight plugin toggle flashlight in Intel XDK.
Installing Flashlight Plugin
Follow these steps to open remote plugin install box Projects → Select your project → Plugins and Permissions → Third-Party plugins → Get plugin from web. Now enter name as “Flashlight”, Plugin ID as “nl.x-services.plugins.flashlight” and Repo URL as “https://github.com/EddyVerbruggen/Flashlight-PhoneGap-Plugin.git”. Then click Import.
Now add this script tag to your source code
Flashlight API
Here is the code to toggle flashlight
{
window.plugins.flashlight.available(function(isAvailable) {
if (isAvailable) {
window.plugins.flashlight.toggle(function(){
alert("Success");
}, function(){
alert("Failure");
});
} else {
alert("Flashlight not available on this device");
}
});
}
Testing
Emulator doesn’t support flashlight emulation. APP Preview doesn’t support installation of plugins. Therefore you need to build the app to test it. Third party plugins don’t work in legacy apps therefore you have to build a cordova hybrid app.