npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ionic-native-ohos/file-opener

v5.36.0

Published

Ionic Native - Native plugins for ionic apps

Readme

@ionic-native/file-opener

zh-CN en

本项目基于@ionic-native/[email protected]开发。

简介

@ionic-native/file-opener是OpenHarmony Cordova生态系统中的核心插件,提供使用默认应用程序打开设备文件系统上文件的功能,为跨平台应用开发提供设备差异化适配能力。兼容Android、iOS和OpenHarmony平台,为跨平台应用开发提供统一的文件打开能力。本文档主要说明在OpenHarmony系统中的应用。

@ionic-native/file-openerAPI提供使用默认应用程序打开文件的功能。

支持平台

  • OpenHarmony:5.0+

下载安装

通过命令行或手动引入即可快速安装插件,支持从npm仓库获取。

命令行安装(推荐)

安装hionic CLI:

npm install -g hionic

以下两种方式中任选其一即可,无需重复操作:

npm安装:

# 安装插件
npm install @ionic-native/file-opener

# 同步插件
hionic sync

hionic CLI安装:

hionic plugin add @ionic-native/file-opener

手动引入安装

1.添加插件配置

根据 plugin.xmlconfig-json 项,找到 entry 模块中 config.xml 文件,并根据 param 标签添加配置

<feature name="FileOpener2">
  <param name="harmony-package" value="FileOpener2" />
</feature>

2.修改CMake配置

根据 plugin.xmlCMakeLists 项,找到 cordova 模块,路径为 target 字段的文件 CMakeLists.txt,添加 add_library

add_library(cordova SHARED
  // ...
  FileOpener2/FileOpener2.cpp
  // ...
)

3.复制源码文件

根据 plugin.xmlsource-file 项,将 src 字段的路径代码复制到 cordova 模块中 target-dir 字段的目录中:

将源码中src/main/cpp/FileOpener2目录下的FileOpener2.h、FileOpener2.cpp文件引入到cordova模块中 src/main/cpp/FileOpener2目录下。

将源码中src/main/ets/components/FileOpener2目录下的FileOpener2.ets文件引入到cordova模块中src/main/ets/components/FileOpener2目录下。

4.添加ArkTS配置

cordova 模块的 build-profile.json5 文件中,buildOption/arkOptions/runtimeOnly/sources 配置项数组中加入步骤3中拷贝的ets文件路径:

"buildOption":{
  "arkOptions": {
    "runtimeOnly": {
      "sources": [
        // ...
        "./src/main/ets/components/FileOpener2/FileOpener2.ets"
        // ...
      ]
    }
  }
}

卸载

# hionic CLI 卸载
hionic plugin remove @ionic-native/file-opener

约束与限制

兼容性

在以下版本中已测试通过:

  1. SDK: 5.0.5(17); IDE: DevEco Studio: 6.0.0; ROM: 5.1.0.150;

使用示例

示例1:打开一个文件

实现使用默认应用程序打开设备文件系统上的文件。

import { FileOpener } from '@ionic-native/file-opener';

await FileOpener.open(filePath, mimeType);

示例2:以系统模态打开文件

实现以系统模态打开文件并使用已安装的应用程序打开。

await FileOpener.showOpenWithDialog(filePath, mimeType);

示例3:检查应用是否已安装

检查应用是否已安装。需要在module.json5中配置querySchemes,被判断的app需要在module.json5中配置scheme。

const res = await FileOpener.appIsInstalled(packageId);

示例4:卸载应用

实现卸载指定包名的应用。

const res = await FileOpener.uninstall(packageId);

使用说明

接口方法

| 方法名 | 请求参数 | 返回类型 | 描述 | 备注 | |-------|---------|---------|------|------| | open(...) | open(filePath: string, fileMIMEType: string) | Promise<string> | 使用默认应用程序打开文件 | | | showOpenWithDialog(...) | showOpenWithDialog(filePath: string, mimeType: string) | Promise<string> | 以系统模态打开文件并使用已安装的应用程序打开 | | | appIsInstalled(...) | appIsInstalled(packageId: string) | Promise<string> | 检查应用是否已安装 | | | uninstall(...) | uninstall(packageId: string) | Promise<string> | 卸载应用 | |

方法参数说明

1. 使用默认应用程序打开文件

FileOpener.open(
  filePath: string, // 文件路径
  fileMIMEType: string, // 文件MIME类型
): Promise<string>;

2. 以系统模态打开文件

FileOpener.showOpenWithDialog(
  filePath: string, // 文件路径
  mimeType: string, // 文件MIME类型
): Promise<string>;

3. 检查应用是否已安装

FileOpener.appIsInstalled(
  packageId: string, // 应用包名
): Promise<string>;

4. 卸载应用

FileOpener.uninstall(
  packageId: string, // 应用包名
): Promise<string>;

目录结构

|---- 目录
|     |---- src/main  # 插件的实现代码
|           |---- cpp  # C++ 代码
|           |---- ets  # ArkTS 代码
|     |---- www    # Web 侧代码
|     |---- README.md          # 说明文档
|     |---- package.json       # 配置文件
|     |---- plugin.xml         # 插件配置文件

贡献代码

使用过程中发现任何问题都可以提Issue,当然,也非常欢迎发PR共建。

许可证

本插件基于MIT License开源,详见LICENSE文件。