跳过主要内容
返回插件
@capgo/capacitor-flash
教程
由 github.com/Cap-go

Flash

使用简单的开关功能控制设备的闪光灯和手电筒

指南

关于闪光灯的教程

使用@capgo/capacitor-flash

Capacitor用于控制设备闪光灯/手电筒的插件

安装

bun add @capgo/capacitor-flash
bunx cap sync

此插件暴露了什么

  • isAvailable - 检查设备上是否有闪光灯功能
  • switchOn - 打开闪光灯
  • switchOff - 关闭闪光灯
  • isSwitchedOn - 检查手电筒是否处于开启或关闭状态。

示例用法

isAvailable

检查设备上手电筒的可用性。

import { CapacitorFlash } from '@capgo/capacitor-flash';

const { value } = await CapacitorFlash.isAvailable();
if (value) {
  console.log('Flashlight is available');
}

switchOn

开启手电筒。

import { CapacitorFlash } from '@capgo/capacitor-flash';

// Turn on at full brightness
await CapacitorFlash.switchOn({ intensity: 1.0 });

// Turn on at half brightness
await CapacitorFlash.switchOn({ intensity: 0.5 });

switchOff

关闭手电筒。

import { CapacitorFlash } from '@capgo/capacitor-flash';

await CapacitorFlash.switchOff();

isSwitchedOn

检查手电筒是否处于开启或关闭状态。

import { CapacitorFlash } from '@capgo/capacitor-flash';

const { value } = await CapacitorFlash.isSwitchedOn();
console.log('Flashlight is on:', value);

全局参考