跳过主要内容

指南

Flash教程

在设备上测试

Download the Capgo app, then scan the QR code.

Flash插件预览二维码code

使用@capgo/capacitor-flash

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

安装

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);

完整参考文档

继续使用@capgo/capacitor-flash

如果您正在使用 使用@capgo/capacitor-flash 规划仪表板和API操作时,连接它与 @capgo/capacitor-flash 为 @capgo/capacitor-flash 的实现细节 开始使用 为开始使用的实现细节 API 简介 为 API 简介的实现细节 介绍 为介绍和 API 密钥 为 API 密钥的实现细节