@capawesome/capacitor-torch

中文文档
8.0.2发布于 2026/09/02MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 2.5万

Capacitor plugin for switching the flashlight on and off on Android, iOS, and Web.

原始使用文档
文档目录29 节
  1. Features
  2. Use Cases
  3. Compatibility
  4. Installation
  5. Android
  6. Configuration
  7. Demo
  8. Usage
  9. Check if the torch is available
  10. Turn the torch on and off
  11. Toggle the torch
  12. Check if the torch is enabled
  13. API
  14. enable(...)
  15. disable(...)
  16. isAvailable()
  17. isEnabled(...)
  18. toggle(...)
  19. Interfaces
  20. FAQ
  21. Which platforms are supported by this plugin?
  22. Why does isAvailable return false on my device?
  23. Do I need any permissions to use this plugin?
  24. How does the torch control work on the web?
  25. Can I use this plugin with Ionic, React, Vue or Angular?
  26. Related Plugins
  27. Newsletter
  28. Changelog
  29. License

Capacitor Torch Plugin

Capacitor plugin for switching the flashlight on and off.

Features

The Capacitor Torch plugin is one of the most complete flashlight control solutions for Capacitor apps. Here are some of the key features:

  • 🖥️ Cross-platform: Supports Android, iOS, and Web.
  • 🔦 Torch control: Enable, disable, and toggle torch/flashlight.
  • ✅ Availability check: Check if torch is available on the device.
  • 🌐 Web support: Uses MediaStream API for web torch control.
  • 🤝 Compatibility: Works alongside the Barcode Scanning and Light Sensor plugins.
  • 🔁 Up-to-date: Always supports the latest Capacitor version.

Missing a feature? Just open an issue and we'll take a look!

Use Cases

The Torch plugin is typically used whenever an app needs to control the device's flashlight, for example:

  • Flashlight features: Turn the flashlight on and off with a single tap in your app.
  • Barcode and QR code scanning: Let users enable the torch to scan codes in low-light environments.
  • Document capture: Improve capture quality in dark surroundings by enabling the torch.
  • Signaling: Toggle the torch to draw attention, for example as an emergency signal light.

Compatibility

Plugin VersionCapacitor VersionStatus
8.x.x>=8.x.xActive support

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills --skill capacitor-plugins

Then use the following prompt:

 Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-torch` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capawesome/capacitor-torch
npx cap sync

Android

Permissions

This API requires the following permissions be added to your AndroidManifest.xml before the application tag:

<!-- To get access to the flashlight. -->
<uses-permission android:name="android.permission.FLASHLIGHT"/>

Variables

If needed, you can define the following project variable in your app’s variables.gradle file to change the default version of the dependency:

  • $androidxCameraCoreVersion version of androidx.camera:camera-core (default: 1.5.2)

This can be useful if you encounter dependency conflicts with other plugins in your project.

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-plugin-demo

Usage

The following examples show how to check if the torch is available, turn the torch on and off, toggle the torch, and check if the torch is enabled.

Check if the torch is available

Not every device has a torch, so check the availability before showing a flashlight control in your UI:

import { Torch } from '@capawesome/capacitor-torch';

const isAvailable = async () => {
    const result = await Torch.isAvailable();
    return result.available;
};

Turn the torch on and off

Enable or disable the torch. On Android, these methods require SDK 23 or newer. On the Web, you can optionally pass your own MediaStream with a video track via the stream option:

import { Torch } from '@capawesome/capacitor-torch';

const enable = async () => {
  await Torch.enable();
};

const disable = async () => {
  await Torch.disable();
};

Toggle the torch

Switch the torch to the opposite state with a single call:

import { Torch } from '@capawesome/capacitor-torch';

const toggle = async () => {
  await Torch.toggle();
};

Check if the torch is enabled

Read the current state of the torch, for example to display the state in your UI:

import { Torch } from '@capawesome/capacitor-torch';

const isEnabled = async () => {
    const result = await Torch.isEnabled();
    return result.enabled;
};

API

enable(...)

enable(options?: EnableOptions | undefined) => Promise<void>

Enable the torch.

Only available on Android (SDK 23+), iOS and Web.

ParamType
optionsEnableOptions

Since: 6.0.0


disable(...)

disable(options?: DisableOptions | undefined) => Promise<void>

Disable the torch.

Only available on Android (SDK 23+), iOS and Web.

ParamType
optionsDisableOptions

Since: 6.0.0


isAvailable()

isAvailable() => Promise<IsAvailableResult>

Check if the torch is available.

Only available on Android, iOS and Web.

Returns: Promise<IsAvailableResult>

Since: 6.0.0


isEnabled(...)

isEnabled(options?: IsEnabledOptions | undefined) => Promise<IsEnabledResult>

Check if the torch is enabled.

Only available on Android, iOS and Web.

ParamType
optionsIsEnabledOptions

Returns: Promise<IsEnabledResult>

Since: 6.0.0


toggle(...)

toggle(options?: ToggleOptions | undefined) => Promise<void>

Toggle the torch.

Only available on Android (SDK 23+), iOS and Web.

ParamType
optionsToggleOptions

Since: 6.0.0


Interfaces

EnableOptions

PropTypeDescriptionSince
streamMediaStreamThe stream of media to enable the torch on. Attention: The stream must have a video track. The facing mode of the video track must be the one that corresponds to the torch. Only available on Web.6.2.0

DisableOptions

PropTypeDescriptionSince
streamMediaStreamThe stream of media to disable the torch on. Attention: The stream must have a video track. The facing mode of the video track must be the one that corresponds to the torch. Only available on Web.6.2.0

IsAvailableResult

PropTypeDescriptionSince
availablebooleanWhether the torch is available or not.6.0.0

IsEnabledResult

PropTypeDescriptionSince
enabledbooleanWhether the torch is enabled or not.6.0.0

IsEnabledOptions

PropTypeDescriptionSince
streamMediaStreamThe stream of media to check if the torch is enabled on. Attention: The stream must have a video track. The facing mode of the video track must be the one that corresponds to the torch. Only available on Web.6.2.0

ToggleOptions

PropTypeDescriptionSince
streamMediaStreamThe stream of media to toggle the torch on. Attention: The stream must have a video track. The facing mode of the video track must be the one that corresponds to the torch. Only available on Web.6.2.0

FAQ

Which platforms are supported by this plugin?

The plugin is available on Android, iOS and Web. On Android, the enable(...), disable(...) and toggle(...) methods require SDK 23 or newer. On the Web, the plugin uses the MediaStream API to control the torch.

Why does isAvailable return false on my device?

The isAvailable() method reports whether the current device provides a torch. It returns false on devices without a torch, for example many tablets or desktop browsers. Use this method to hide or disable your flashlight UI on such devices.

Do I need any permissions to use this plugin?

On Android, you need to add the FLASHLIGHT permission to your AndroidManifest.xml file, see the Installation section. No permissions are required on iOS.

How does the torch control work on the web?

The web implementation uses the MediaStream API. You can optionally pass your own MediaStream via the stream option of enable(...), disable(...), isEnabled(...) and toggle(...). The stream must have a video track, and the facing mode of the video track must be the one that corresponds to the torch.

Can I use this plugin with Ionic, React, Vue or Angular?

Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Changelog

See CHANGELOG.md.

License

See LICENSE.

版本与发布记录

@capawesome/capacitor-torch 共发布 11 个版本,首次发布于 2024/09/12;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.0.2latest2026/09/022 个月前
8.0.12026/02/198 个月前
8.0.02025/12/1710 个月前
7.0.0-dev.1765885034dev2025/12/1610 个月前
7.0.22025/02/191.7 年前
7.0.12025/02/011.8 年前

关于 @capawesome/capacitor-torch 的常见问题

@capawesome/capacitor-torch 是什么?

Capacitor plugin for switching the flashlight on and off on Android, iOS, and Web.

如何安装 @capawesome/capacitor-torch?

在项目目录运行 npm install @capawesome/capacitor-torch,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capawesome/capacitor-torch 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capawesome/capacitor-torch 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capawesome/capacitor-torch 可以商用吗?

@capawesome/capacitor-torch 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@capawesome/capacitor-torch 的下载量有多少?

根据 npm 官方下载统计,@capawesome/capacitor-torch 在 2026/10/09 – 2026/11/07 这 30 天内被下载 25,149 次,日均约 838 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capawesome/capacitor-torch 还在维护吗?

最新版本 8.0.2 发布于 2026/09/02(2 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 4 个;首次发布于 2024/09/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。