@capawesome-team/capacitor-file-opener

中文文档
8.1.1发布于 2026/10/28MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 12.2万

Capacitor plugin to open a file with the default application on Android, iOS, and Web.

原始使用文档
文档目录24 节
  1. Features
  2. Use Cases
  3. Compatibility
  4. Demo
  5. Guides
  6. Installation
  7. Android
  8. Configuration
  9. Usage
  10. Open a file with the default application
  11. API
  12. openFile(...)
  13. Interfaces
  14. FAQ
  15. Which file types can I open with this plugin?
  16. Why can't a file be opened on Android?
  17. How do I open a file on the Web?
  18. Do I need to specify the mime type of the file?
  19. How is this plugin different from the File Picker plugin?
  20. Can I use this plugin with Ionic, React, Vue or Angular?
  21. Related Plugins
  22. Newsletter
  23. Changelog
  24. License

Capacitor File Opener Plugin

Capacitor plugin to open a file with the default application.

Features

The Capacitor File Opener plugin is one of the most complete file opening solutions for Capacitor apps. Here are some of the key features:

  • 🖥️ Cross-platform: Supports Android, iOS, and Web.
  • 📄 Multiple file formats: Open various file types with their default applications.
  • 🌐 Web support: Open files using Blob objects on Web platform.
  • 📱 Native integration: Uses system file associations on mobile platforms.
  • 📁 Flexible paths: Support for file paths and content URIs on Android.
  • 🔍 MIME type detection: Automatic MIME type detection or manual specification.
  • 🚨 Error Codes: Provides detailed error codes for better error handling.
  • 🤝 Compatibility: Works alongside the File Compressor, File Picker and Printer 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 File Opener plugin is typically used whenever an app hands a file over to another application, for example:

  • Document viewing: Open downloaded documents such as PDFs, invoices, or reports with the device's default viewer app.
  • Post-download handling: Let users open a file right after your app has downloaded or generated it.
  • Media playback: Open images, videos, or audio files with the app the user has associated with that file type.
  • Web downloads: Open files from Blob objects on the Web without saving them first.

Compatibility

Plugin VersionCapacitor VersionStatus
8.x.x>=8.x.xActive support
7.x.x7.x.xDeprecated
6.x.x6.x.xDeprecated
5.x.x5.x.xDeprecated

Demo

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

AndroidiOS
Android DemoiOS Demo

Guides

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-team/capacitor-file-opener` 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-team/capacitor-file-opener
npx cap sync

Android

You need to specify the directories that contain the files you want to open. To do this, create a new file named file_paths.xml in the res/xml directory of your Android project (e.g. android/app/src/main/res/xml/file_paths.xml). Here is an example of the content of the file:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="files" path="." />
    <cache-path name="cache" path="." />
    <external-files-path name="external-files" path="." />
    <external-cache-path name="external-cache" path="." />
    <external-path name="external" path="." />
</paths>

More information can be found in the Android documentation.

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:

  • $androidxDocumentFileVersion version of androidx.documentfile:documentfile (default: 1.1.0)

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

Configuration

No configuration required for this plugin.

Usage

The following example shows how to open a file with the default application.

Open a file with the default application

On Android and iOS, pass the path of the file. On Android, both file paths and content URIs are supported. The mime type is determined automatically, but you can also specify it with the mimeType option. On Web, pass a Blob instance instead:

import { ErrorCode, FileOpener } from '@capawesome-team/capacitor-file-opener';

const open = async () => {
  try {
    await FileOpener.openFile({
      path: 'content://com.android.providers.downloads.documents/document/msf%3A1000000073',
    });
  } catch (error) {
    if (error.code === ErrorCode.FileAlreadyOpen) {
      // On iOS, a file is already open or still being opened.
    } else {
      // Handle other errors.
    }
  }
};

API

openFile(...)

openFile(options: OpenFileOptions) => Promise<void>

Open a file with the default application.

ParamType
optionsOpenFileOptions

Since: 0.0.1


Interfaces

OpenFileOptions

PropTypeDescriptionSince
blobBlobThe blob instance of the file to open. Only available on Web.6.1.0
pathstringThe path of the file. Only available on Android and iOS.0.0.1
mimeTypestringThe mime type of the file. If not specified, the mime type will be determined. Only available on Android and iOS.0.0.1

FAQ

Which file types can I open with this plugin?

The plugin can open various file types with their default applications. On Android and iOS, it uses the system file associations, so any file type for which the user has a suitable app installed can be opened. The mime type is determined automatically, but you can also specify it manually with the mimeType option.

Why can't a file be opened on Android?

Make sure that the directory containing the file is declared in the file_paths.xml file of your Android project, as described in the Installation section. Without this configuration, the file can not be shared with the app that should open it.

How do I open a file on the Web?

On the Web, pass a Blob instance to the openFile(...) method using the blob option. The path and mimeType options are only available on Android and iOS.

Do I need to specify the mime type of the file?

No, if the mimeType option is not specified, the mime type will be determined automatically. You only need to set it if you want to override the detected type. This option is only available on Android and iOS.

How is this plugin different from the File Picker plugin?

The File Picker plugin lets the user select a file from the device and returns its path and metadata. The File Opener plugin does the opposite: it takes a file your app already has and opens it with the default application. Both plugins work well together, for example to pick a file and then open it.

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.

  • File Compressor: Compress files with support for image formats like PNG, JPEG, and WebP.
  • File Picker: Let the user select a file, directory, image, or video from the device.
  • Printer: Print files, HTML, PDFs, and web views on Android and iOS.
  • Share Target: Receive text, links, and files shared from other apps.

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-team/capacitor-file-opener 共发布 20 个版本,首次发布于 2022/12/10;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.1.1latest2026/10/2811 天前
8.1.02026/10/2119 天前
8.0.62026/10/1623 天前
8.0.52026/09/181 个月前
8.0.42026/09/052 个月前
8.0.32026/09/022 个月前

关于 @capawesome-team/capacitor-file-opener 的常见问题

@capawesome-team/capacitor-file-opener 是什么?

Capacitor plugin to open a file with the default application on Android, iOS, and Web.

如何安装 @capawesome-team/capacitor-file-opener?

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

@capawesome-team/capacitor-file-opener 支持 TypeScript 吗?

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

@capawesome-team/capacitor-file-opener 支持 ESM 还是 CommonJS?

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

@capawesome-team/capacitor-file-opener 可以商用吗?

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

@capawesome-team/capacitor-file-opener 的下载量有多少?

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

@capawesome-team/capacitor-file-opener 还在维护吗?

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