Search code examples
ionic-frameworkionic3ionic-native

how turn on flashlight when use camera ionic 3


I am currently using the camera Preview plugin in ionic 3, I have created a button to activate the flashlight plugin but when calling the method it returns null

 if (this.flashlight.available()) {
       this.isOn = false;
       this.flashlight.isSwitchedOn() ? this.flashlight.switchOff() : this.flashlight.switchOn();
     } else {
       alert('Flashlight Not Available');
     }

I want to have that button to use the flash as a flashlight while I using the camera.


Solution

  • You can use setFlashMode Method to set flash status

      flashMode = 'on';
      changeFlashMode() {
       this.cameraPreview.setFlashMode(this.flashMode);
      }
    

    you can see this full article that do what you want to do from here