@code_ai_labs/capacitor-flashlight
v1.0.2
Published
Capacitor plugin for an Ionic app that controls the device's flashlight
Downloads
10
Readme
A Capacitor plugin for controlling the device's flashlight - works on Android and iOS
Installation
npm install @code_ai_labs/capacitor-flashlight
npx cap syncUsage
import { Flashlight } from '@code_ai_labs/capacitor-flashlight';
// Turn on the flashlight
const turnOnFlashlight = async () => {
try {
await Flashlight.turnOn();
console.log('Flashlight turned on successfully');
} catch (error) {
console.error('Error turning on flashlight:', error);
}
};
// Turn off the flashlight
const turnOffFlashlight = async () => {
try {
await Flashlight.turnOff();
console.log('Flashlight turned off successfully');
} catch (error) {
console.error('Error turning off flashlight:', error);
}
};
// Toggle the flashlight state
const toggleFlashlight = async () => {
try {
await Flashlight.toggle();
console.log('Flashlight toggled successfully');
} catch (error) {
console.error('Error toggling flashlight:', error);
}
};Required Permissions
Android
Add these to your AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.flash" />iOS
Add this to your Info.plist:
<key>NSCameraUsageDescription</key>
<string>We need access to the camera to control the flashlight</string>API
turnOn()
turnOn() => Promise<void>Turn on the device's flashlight.
Since: 1.0.0
turnOff()
turnOff() => Promise<void>Turn off the device's flashlight.
Since: 1.0.0
toggle()
toggle() => Promise<void>Toggle the device's flashlight on/off.
Since: 1.0.0
License
MIT
