@ionic-native-ohos/file-opener 5.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright 2015-present Drifty Co.
2
+ http://drifty.com/
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/OAT.xml ADDED
@@ -0,0 +1,79 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ The MIT License (MIT)
4
+ Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+ -->
16
+
17
+ <configuration>
18
+ <oatconfig>
19
+ <licensefile></licensefile>
20
+ <policylist>
21
+ <policy name="projectPolicy" desc="">
22
+ <!--policyitem type="compatibility" name="GPL-2.0+" path="abc/.*" desc="Process that runs independently, invoked by the X process."/-->
23
+ <policyitem type="license" name="MIT" path=".*" desc="MIT"/>
24
+ <policyitem type="copyright"
25
+ name="Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd."
26
+ path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter"
27
+ desc="Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd."/>
28
+ </policy>
29
+ </policylist>
30
+ <filefilterlist>
31
+ <filefilter name="defaultFilter" desc="Files not to check">
32
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
33
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
34
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
35
+ </filefilter>
36
+ <filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
37
+ <filteritem type="filepath" name="www/plugins.FileOpener2.js" desc="引用开源上游社区代码"/>
38
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
39
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
40
+ </filefilter>
41
+ <filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
42
+ <filteritem type="filepath" name="www/plugins.FileOpener2.js" desc="引用开源上游社区代码"/>
43
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
44
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
45
+ </filefilter>
46
+ <filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
47
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
48
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
49
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
50
+ </filefilter>
51
+ <filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
52
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
53
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
54
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
55
+ </filefilter>
56
+ <filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies">
57
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
58
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
59
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
60
+ </filefilter>
61
+ <filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
62
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
63
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
64
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
65
+ </filefilter>
66
+
67
+ </filefilterlist>
68
+ <licensematcherlist>
69
+ <!--licensematcher name="uvwxyz License" desc="If the scanning result is InvalidLicense, you can define matching rules here. Note that quotation marks must be escaped.">
70
+ <licensetext name="
71
+ uvwxyz license textA xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
72
+ " desc=""/>
73
+ <licensetext name="
74
+ uvwxyz license textB xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
75
+ " desc=""/>
76
+ </licensematcher-->
77
+ </licensematcherlist>
78
+ </oatconfig>
79
+ </configuration>
package/README.en.md ADDED
@@ -0,0 +1,214 @@
1
+ # <center>@ionic-native/file-opener</center>
2
+ [![zh-CN](https://img.shields.io/badge/lang-中文-blue.svg)](README.md)
3
+ [![en](https://img.shields.io/badge/lang-English-blue.svg)](README.en.md)
4
+
5
+ This project is developed based on [@ionic-native/file-opener@5.36.0](https://www.npmjs.com/package/@ionic-native/file-opener/v/5.36.0).
6
+
7
+ ## Introduction
8
+
9
+ `@ionic-native/file-opener` is a core plugin in the OpenHarmony Cordova ecosystem. It provides the capability to open files on the device file system with default applications, offering device-differentiated adaptation for cross-platform app development. It is compatible with Android, iOS, and OpenHarmony platforms, and provides unified file-opening capabilities for cross-platform app development. This document mainly describes usage on the OpenHarmony system.
10
+
11
+ The `@ionic-native/file-opener` API provides functions for opening files using default applications.
12
+
13
+ ## Supported Platforms
14
+
15
+ - **OpenHarmony**: 5.0+
16
+
17
+ ## Installation
18
+
19
+ You can quickly install the plugin through command-line installation or manual integration. Installation from the npm repository is supported.
20
+
21
+ ### Command-line Installation (Recommended)
22
+
23
+ Install hionic CLI:
24
+
25
+ ```bash
26
+ npm install -g hionic
27
+ ```
28
+
29
+ Choose **one of the following two methods** only.
30
+
31
+ npm installation:
32
+
33
+ ```bash
34
+ # Install plugin
35
+ npm install @ionic-native/file-opener
36
+
37
+ # Sync plugin
38
+ hionic sync
39
+ ```
40
+
41
+ hionic CLI installation:
42
+
43
+ ```bash
44
+ hionic plugin add @ionic-native/file-opener
45
+ ```
46
+
47
+ ### Manual Integration
48
+
49
+ #### 1. Add Plugin Configuration
50
+
51
+ According to the `config-json` item in `plugin.xml`, locate the `config.xml` file in the `entry` module and add configuration according to the `param` tag:
52
+
53
+ ```xml
54
+ <feature name="FileOpener2">
55
+ <param name="harmony-package" value="FileOpener2" />
56
+ </feature>
57
+ ```
58
+
59
+ #### 2. Update CMake Configuration
60
+
61
+ According to the `CMakeLists` item in `plugin.xml`, locate module `cordova`. The path is the `CMakeLists.txt` file specified by the `target` field. Add `add_library`:
62
+
63
+ ```
64
+ add_library(cordova SHARED
65
+ // ...
66
+ FileOpener2/FileOpener2.cpp
67
+ // ...
68
+ )
69
+ ```
70
+
71
+ #### 3. Copy Source Files
72
+
73
+ According to the `source-file` item in `plugin.xml`, copy source code from the `src` path into the directory specified by `target-dir` in the `cordova` module:
74
+
75
+ Copy `FileOpener2.h` and `FileOpener2.cpp` from `src/main/cpp/FileOpener2` in the source code to `src/main/cpp/FileOpener2` in the cordova module.
76
+
77
+ Copy `FileOpener2.ets` from `src/main/ets/components/FileOpener2` in the source code to `src/main/ets/components/FileOpener2` in the cordova module.
78
+
79
+ #### 4. Add ArkTS Configuration
80
+
81
+ In the `build-profile.json5` file of the `cordova` module, add the ets file path copied in step 3 to the `buildOption/arkOptions/runtimeOnly/sources` configuration array:
82
+
83
+ ```
84
+ "buildOption":{
85
+ "arkOptions": {
86
+ "runtimeOnly": {
87
+ "sources": [
88
+ // ...
89
+ "./src/main/ets/components/FileOpener2/FileOpener2.ets"
90
+ // ...
91
+ ]
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ ## Uninstallation
98
+
99
+ ```bash
100
+ # Uninstall via hionic CLI
101
+ hionic plugin remove @ionic-native/file-opener
102
+ ```
103
+
104
+ ## Constraints and Limitations
105
+
106
+ ### Compatibility
107
+
108
+ Tested successfully on the following version:
109
+
110
+ 1. SDK: 5.0.5(17); IDE: DevEco Studio: 6.0.0; ROM: 5.1.0.150;
111
+
112
+ ## Usage Examples
113
+
114
+ ### Example 1: Open a file
115
+
116
+ Open a file on the device file system using the default application.
117
+
118
+ ```javascript
119
+ import { FileOpener } from '@ionic-native/file-opener';
120
+
121
+ await FileOpener.open(filePath, mimeType);
122
+ ```
123
+
124
+ ### Example 2: Open file with system modal
125
+
126
+ Open file with system modal and use installed applications to open it.
127
+
128
+ ```javascript
129
+ await FileOpener.showOpenWithDialog(filePath, mimeType);
130
+ ```
131
+
132
+ ### Example 3: Check whether app is installed
133
+
134
+ Check whether an app is installed. `querySchemes` must be configured in `module.json5`, and the target app must configure `scheme` in `module.json5`.
135
+
136
+ ```javascript
137
+ const res = await FileOpener.appIsInstalled(packageId);
138
+ ```
139
+
140
+ ### Example 4: Uninstall app
141
+
142
+ Uninstall app with specified package name.
143
+
144
+ ```javascript
145
+ const res = await FileOpener.uninstall(packageId);
146
+ ```
147
+
148
+ ## Usage Guide
149
+
150
+ ### API Methods
151
+
152
+ | Method Name | Request Parameters | Return Type | Description | Notes |
153
+ |-------|---------|---------|------|------|
154
+ | `open(...)` | open(filePath: string, fileMIMEType: string) | `Promise<string>` | Open file using default application | |
155
+ | `showOpenWithDialog(...)` | showOpenWithDialog(filePath: string, mimeType: string) | `Promise<string>` | Open file with system modal and use installed applications | |
156
+ | `appIsInstalled(...)` | appIsInstalled(packageId: string) | `Promise<string>` | Check whether app is installed | |
157
+ | `uninstall(...)` | uninstall(packageId: string) | `Promise<string>` | Uninstall app | |
158
+
159
+ ### Method Parameter Description
160
+
161
+ #### 1. Open file using default application
162
+
163
+ ```javascript
164
+ FileOpener.open(
165
+ filePath: string, // File path
166
+ fileMIMEType: string, // File MIME type
167
+ ): Promise<string>;
168
+ ```
169
+
170
+ #### 2. Open file with system modal
171
+
172
+ ```javascript
173
+ FileOpener.showOpenWithDialog(
174
+ filePath: string, // File path
175
+ mimeType: string, // File MIME type
176
+ ): Promise<string>;
177
+ ```
178
+
179
+ #### 3. Check whether app is installed
180
+
181
+ ```javascript
182
+ FileOpener.appIsInstalled(
183
+ packageId: string, // App package name
184
+ ): Promise<string>;
185
+ ```
186
+
187
+ #### 4. Uninstall app
188
+
189
+ ```javascript
190
+ FileOpener.uninstall(
191
+ packageId: string, // App package name
192
+ ): Promise<string>;
193
+ ```
194
+
195
+ ## Directory Structure
196
+
197
+ ```
198
+ |---- Directory
199
+ | |---- src/main # Plugin implementation code
200
+ | |---- cpp # C++ code
201
+ | |---- ets # ArkTS code
202
+ | |---- www # Web-side code
203
+ | |---- README.md # Documentation
204
+ | |---- package.json # Configuration file
205
+ | |---- plugin.xml # Plugin configuration file
206
+ ```
207
+
208
+ ## Contributing
209
+
210
+ If you find any issues during usage, you can submit an [Issue](https://gitcode.com/CPF-Ionic/ionic-native-file-opener/issues). You are also very welcome to submit a [PR](https://gitcode.com/CPF-Ionic/ionic-native-file-opener/pulls) for co-development.
211
+
212
+ ## License
213
+
214
+ This plugin is open-sourced under the **MIT License**. See the [LICENSE](./LICENSE) file for details.
package/README.md ADDED
@@ -0,0 +1,211 @@
1
+ # <center>@ionic-native/file-opener</center>
2
+ [![zh-CN](https://img.shields.io/badge/lang-中文-blue.svg)](README.md)
3
+ [![en](https://img.shields.io/badge/lang-English-blue.svg)](README.en.md)
4
+
5
+ 本项目基于[@ionic-native/file-opener@5.36.0](https://www.npmjs.com/package/@ionic-native/file-opener/v/5.36.0)开发。
6
+
7
+ ## 简介
8
+
9
+ `@ionic-native/file-opener`是OpenHarmony Cordova生态系统中的核心插件,提供使用默认应用程序打开设备文件系统上文件的功能,为跨平台应用开发提供设备差异化适配能力。兼容Android、iOS和OpenHarmony平台,为跨平台应用开发提供统一的文件打开能力。本文档主要说明在OpenHarmony系统中的应用。
10
+
11
+ `@ionic-native/file-opener`API提供使用默认应用程序打开文件的功能。
12
+
13
+ ## 支持平台
14
+
15
+ - **OpenHarmony**:5.0+
16
+
17
+ ## 下载安装
18
+
19
+ 通过命令行或手动引入即可快速安装插件,支持从npm仓库获取。
20
+
21
+ ### 命令行安装(推荐)
22
+
23
+ 安装hionic CLI:
24
+
25
+ ```bash
26
+ npm install -g hionic
27
+ ```
28
+
29
+ 以下两种方式中**任选其一**即可,无需重复操作:
30
+
31
+ npm安装:
32
+
33
+ ```bash
34
+ # 安装插件
35
+ npm install @ionic-native/file-opener
36
+
37
+ # 同步插件
38
+ hionic sync
39
+ ```
40
+
41
+ hionic CLI安装:
42
+
43
+ ```bash
44
+ hionic plugin add @ionic-native/file-opener
45
+ ```
46
+
47
+ ### 手动引入安装
48
+
49
+ #### 1.添加插件配置
50
+
51
+ 根据 `plugin.xml` 的 `config-json` 项,找到 `entry` 模块中 `config.xml` 文件,并根据 `param` 标签添加配置
52
+ ```xml
53
+ <feature name="FileOpener2">
54
+ <param name="harmony-package" value="FileOpener2" />
55
+ </feature>
56
+ ```
57
+
58
+ #### 2.修改CMake配置
59
+
60
+ 根据 `plugin.xml` 的 `CMakeLists` 项,找到 `cordova` 模块,路径为 `target` 字段的文件 `CMakeLists.txt`,添加 `add_library`
61
+ ```
62
+ add_library(cordova SHARED
63
+ // ...
64
+ FileOpener2/FileOpener2.cpp
65
+ // ...
66
+ )
67
+ ```
68
+
69
+ #### 3.复制源码文件
70
+
71
+ 根据 `plugin.xml` 的 `source-file` 项,将 `src` 字段的路径代码复制到 `cordova` 模块中 `target-dir` 字段的目录中:
72
+
73
+ 将源码中src/main/cpp/FileOpener2目录下的FileOpener2.h、FileOpener2.cpp文件引入到cordova模块中 src/main/cpp/FileOpener2目录下。
74
+
75
+ 将源码中src/main/ets/components/FileOpener2目录下的FileOpener2.ets文件引入到cordova模块中src/main/ets/components/FileOpener2目录下。
76
+
77
+ #### 4.添加ArkTS配置
78
+
79
+ 在 `cordova` 模块的 `build-profile.json5` 文件中,`buildOption/arkOptions/runtimeOnly/sources` 配置项数组中加入步骤3中拷贝的ets文件路径:
80
+ ```
81
+ "buildOption":{
82
+ "arkOptions": {
83
+ "runtimeOnly": {
84
+ "sources": [
85
+ // ...
86
+ "./src/main/ets/components/FileOpener2/FileOpener2.ets"
87
+ // ...
88
+ ]
89
+ }
90
+ }
91
+ }
92
+ ```
93
+
94
+ ## 卸载
95
+
96
+ ```bash
97
+ # hionic CLI 卸载
98
+ hionic plugin remove @ionic-native/file-opener
99
+ ```
100
+
101
+ ## 约束与限制
102
+
103
+ ### 兼容性
104
+
105
+ 在以下版本中已测试通过:
106
+
107
+ 1. SDK: 5.0.5(17); IDE: DevEco Studio: 6.0.0; ROM: 5.1.0.150;
108
+
109
+ ## 使用示例
110
+
111
+ ### 示例1:打开一个文件
112
+
113
+ 实现使用默认应用程序打开设备文件系统上的文件。
114
+
115
+ ```javascript
116
+ import { FileOpener } from '@ionic-native/file-opener';
117
+
118
+ await FileOpener.open(filePath, mimeType);
119
+ ```
120
+
121
+ ### 示例2:以系统模态打开文件
122
+
123
+ 实现以系统模态打开文件并使用已安装的应用程序打开。
124
+
125
+ ```javascript
126
+ await FileOpener.showOpenWithDialog(filePath, mimeType);
127
+ ```
128
+
129
+ ### 示例3:检查应用是否已安装
130
+
131
+ 检查应用是否已安装。需要在module.json5中配置querySchemes,被判断的app需要在module.json5中配置scheme。
132
+
133
+ ```javascript
134
+ const res = await FileOpener.appIsInstalled(packageId);
135
+ ```
136
+
137
+ ### 示例4:卸载应用
138
+
139
+ 实现卸载指定包名的应用。
140
+
141
+ ```javascript
142
+ const res = await FileOpener.uninstall(packageId);
143
+ ```
144
+
145
+ ## 使用说明
146
+
147
+ ### 接口方法
148
+
149
+ | 方法名 | 请求参数 | 返回类型 | 描述 | 备注 |
150
+ |-------|---------|---------|------|------|
151
+ | `open(...)` | open(filePath: string, fileMIMEType: string) | `Promise<string>` | 使用默认应用程序打开文件 | |
152
+ | `showOpenWithDialog(...)` | showOpenWithDialog(filePath: string, mimeType: string) | `Promise<string>` | 以系统模态打开文件并使用已安装的应用程序打开 | |
153
+ | `appIsInstalled(...)` | appIsInstalled(packageId: string) | `Promise<string>` | 检查应用是否已安装 | |
154
+ | `uninstall(...)` | uninstall(packageId: string) | `Promise<string>` | 卸载应用 | |
155
+
156
+ ### 方法参数说明
157
+
158
+ #### 1. 使用默认应用程序打开文件
159
+
160
+ ```javascript
161
+ FileOpener.open(
162
+ filePath: string, // 文件路径
163
+ fileMIMEType: string, // 文件MIME类型
164
+ ): Promise<string>;
165
+ ```
166
+
167
+ #### 2. 以系统模态打开文件
168
+
169
+ ```javascript
170
+ FileOpener.showOpenWithDialog(
171
+ filePath: string, // 文件路径
172
+ mimeType: string, // 文件MIME类型
173
+ ): Promise<string>;
174
+ ```
175
+
176
+ #### 3. 检查应用是否已安装
177
+
178
+ ```javascript
179
+ FileOpener.appIsInstalled(
180
+ packageId: string, // 应用包名
181
+ ): Promise<string>;
182
+ ```
183
+
184
+ #### 4. 卸载应用
185
+
186
+ ```javascript
187
+ FileOpener.uninstall(
188
+ packageId: string, // 应用包名
189
+ ): Promise<string>;
190
+ ```
191
+
192
+ ## 目录结构
193
+
194
+ ```
195
+ |---- 目录
196
+ | |---- src/main # 插件的实现代码
197
+ | |---- cpp # C++ 代码
198
+ | |---- ets # ArkTS 代码
199
+ | |---- www # Web 侧代码
200
+ | |---- README.md # 说明文档
201
+ | |---- package.json # 配置文件
202
+ | |---- plugin.xml # 插件配置文件
203
+ ```
204
+
205
+ ## 贡献代码
206
+
207
+ 使用过程中发现任何问题都可以提[Issue](https://gitcode.com/CPF-Ionic/ionic-native-file-opener/issues),当然,也非常欢迎发[PR](https://gitcode.com/CPF-Ionic/ionic-native-file-opener/pulls)共建。
208
+
209
+ ## 许可证
210
+
211
+ 本插件基于**MIT License**开源,详见[LICENSE](./LICENSE)文件。
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@ionic-native-ohos/file-opener",
3
+ "version": "5.36.0",
4
+ "description": "Ionic Native - Native plugins for ionic apps",
5
+ "capacitor": {
6
+ "id": "cordova-plugin-file-opener2",
7
+ "platforms": [
8
+ "ohos"
9
+ ]
10
+ },
11
+ "repository": "gitcode:CPF-Ionic/ionic-native-file-opener",
12
+ "bugs": "https://gitcode.com/CPF-Ionic/ionic-plugin-file-opener/issues",
13
+ "keywords": [
14
+ "cordova",
15
+ "file-opener",
16
+ "ecosystem:cordova",
17
+ "cordova-openharmony"
18
+ ],
19
+ "author": "Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd.",
20
+ "license": "MIT"
21
+ }
package/plugin.xml ADDED
@@ -0,0 +1,50 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ The MIT License (MIT)
4
+ Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+ -->
16
+ <plugin
17
+ id="cordova-plugin-file-opener2"
18
+ version="5.36.0">
19
+ <name>@ionic-native/file-opener</name>
20
+ <description>Cordova file-opener Plugin</description>
21
+ <license>MIT</license>
22
+ <keywords>cordova,insomnia</keywords>
23
+ <repo>https://gitcode.com/CPF-Ionic/ionic-native-file-opener.git</repo>
24
+ <issue>https://gitcode.com/CPF-Ionic/ionic-native-file-opener/issues</issue>
25
+
26
+ <engines>
27
+ <engine name="cordova-ohos/ohos" version=">=2.0.0" />
28
+ </engines>
29
+
30
+ <platform name="ohos">
31
+ <config-file target="src/main/resources/rawfile/config.xml" parent="/*" modules-targets-name="default">
32
+ <feature name="FileOpener2">
33
+ <param name="harmony-package" value="FileOpener2" />
34
+ </feature>
35
+ </config-file>
36
+
37
+ <CMakeLists target="src/main/cpp/CMakeLists.txt" modules-name="cordova">
38
+ <param target="add_library" value="FileOpener2/FileOpener2.cpp"/>
39
+ </CMakeLists>
40
+
41
+ <source-file type="h" src="src/main/cpp/FileOpener2/FileOpener2.h" target-dir="src/main/cpp/FileOpener2" modules-name="cordova"/>
42
+ <source-file type="cpp" src="src/main/cpp/FileOpener2/FileOpener2.cpp" target-dir="src/main/cpp/FileOpener2" modules-name="cordova"/>
43
+ <source-file type="ets" src="src/main/ets/components/FileOpener2/FileOpener2.ets" target-dir="src/main/ets/components/FileOpener2" modules-name="cordova" runtimeOnly="true"/>
44
+
45
+ <js-module src="www/plugins.FileOpener2.js" name="FileOpener2" modules-targets-name="default">
46
+ <clobbers target="cordova.plugins.file-opener2" />
47
+ </js-module>
48
+
49
+ </platform>
50
+ </plugin>
@@ -0,0 +1,102 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ * Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ */
15
+
16
+ #include "FileOpener2.h"
17
+ #include "cJSON.h"
18
+
19
+ REGISTER_PLUGIN_CLASS(FileOpener2)
20
+
21
+ bool FileOpener2::execute(const std::string &actionAsString, cJSON *args, CallbackContext cbc)
22
+ {
23
+ if (actionAsString == "onArKTsResult") {
24
+ return onArKTsResult(args);
25
+ } else if (actionAsString == "open") {
26
+ m_cbc = cbc;
27
+ if (cJSON_GetArraySize(args) < paramsTotal2) {
28
+ return true;
29
+ }
30
+ if (cJSON_GetArraySize(args) == paramsTotal2) {
31
+ open(args, cbc);
32
+ } else {
33
+ openWithDialog(args, cbc);
34
+ }
35
+ } else if (actionAsString == "uninstall") {
36
+ m_cbc = cbc;
37
+ if (cJSON_GetArraySize(args) < 1) {
38
+ return true;
39
+ }
40
+ std::string packageId = cJSON_GetArrayItem(args, 0)->valuestring;
41
+ executeArkTs("./FileOpener2/FileOpener2/uninstall", 0, packageId.c_str(), "FileOpener2", cbc);
42
+ } else if (actionAsString == "appIsInstalled") {
43
+ m_cbc = cbc;
44
+ if (cJSON_GetArraySize(args) < 1) {
45
+ return true;
46
+ }
47
+ std::string packageId = cJSON_GetArrayItem(args, 0)->valuestring;
48
+ executeArkTs("./FileOpener2/FileOpener2/appIsInstalled", 0, packageId.c_str(), "FileOpener2", cbc);
49
+ }
50
+ return true;
51
+ }
52
+
53
+ void FileOpener2::open(cJSON *args, CallbackContext cbc)
54
+ {
55
+ cJSON *value1 = cJSON_GetArrayItem(args, 0);
56
+ cJSON *value2 = cJSON_GetArrayItem(args, 1);
57
+ if (value1 && (value1->type == cJSON_String) && value2 && (value2->type == cJSON_String)) {
58
+ std::string filePath = value1->valuestring;
59
+ std::string fileMIMEType = value2->valuestring;
60
+ cJSON *pJson = cJSON_CreateObject();
61
+ cJSON_AddStringToObject(pJson, "filePath", filePath.c_str());
62
+ cJSON_AddStringToObject(pJson, "fileMIMEType", fileMIMEType.c_str());
63
+ executeArkTs("./FileOpener2/FileOpener2/open", 0, cJSON_Print(pJson), "FileOpener2", cbc);
64
+ cJSON_Delete(pJson);
65
+ }
66
+ }
67
+
68
+ void FileOpener2::openWithDialog(cJSON *args, CallbackContext cbc)
69
+ {
70
+ cJSON *value1 = cJSON_GetArrayItem(args, 0);
71
+ cJSON *value2 = cJSON_GetArrayItem(args, 1);
72
+ if (value1 && (value1->type == cJSON_String) && value2 && (value2->type == cJSON_String)) {
73
+ std::string filePath = value1->valuestring;
74
+ std::string fileMIMEType = value2->valuestring;
75
+ cJSON *pJson = cJSON_CreateObject();
76
+ cJSON_AddStringToObject(pJson, "filePath", filePath.c_str());
77
+ cJSON_AddStringToObject(pJson, "fileMIMEType", fileMIMEType.c_str());
78
+ executeArkTs("./FileOpener2/FileOpener2/showOpenWithDialog", 0, cJSON_Print(pJson), "FileOpener2", cbc);
79
+ cJSON_Delete(pJson);
80
+ }
81
+ }
82
+
83
+ bool FileOpener2::onArKTsResult(cJSON *args)
84
+ {
85
+ cJSON *error = cJSON_GetObjectItem(args, "error");
86
+ if (!error) {
87
+ cJSON *action = cJSON_GetObjectItem(args, "action");
88
+ if (action && action->valuestring == "open") {
89
+ m_cbc.success();
90
+ } else if (action->valuestring == "showOpenWithDialog") {
91
+ m_cbc.success();
92
+ } else if (action->valuestring == "appIsInstalled") {
93
+ bool canOpen = cJSON_GetObjectItem(args, "canOpen")->valueint;
94
+ m_cbc.success(canOpen);
95
+ } else if (action->valuestring == "uninstall") {
96
+ m_cbc.success();
97
+ }
98
+ } else {
99
+ m_cbc.error(error->valuestring);
100
+ }
101
+ return true;
102
+ }
@@ -0,0 +1,31 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ * Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ */
15
+
16
+ #ifndef MYAPPLICATION_FILEOPENER2_H
17
+ #define MYAPPLICATION_FILEOPENER2_H
18
+
19
+ #include "CordovaPlugin.h"
20
+
21
+ class FileOpener2 : public CordovaPlugin {
22
+ static const int32_t paramsTotal2 = 2;
23
+ CallbackContext m_cbc;
24
+ public:
25
+ bool execute(const std::string& actionAsString, cJSON* args, CallbackContext cbc) override;
26
+ void open(cJSON *args, CallbackContext cbc);
27
+ void openWithDialog(cJSON *args, CallbackContext cbc);
28
+ bool onArKTsResult(cJSON* args);
29
+ };
30
+
31
+ #endif //MYAPPLICATION_FILEOPENER2_H
@@ -0,0 +1,113 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ * Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ */
15
+
16
+ import { NativeAttribute } from "../PluginGlobal";
17
+ import { bundleManager, common, Want } from "@kit.AbilityKit";
18
+ import { BusinessError } from '@kit.BasicServicesKit';
19
+ import { filePreview } from "@kit.PreviewKit";
20
+ import { fileUri } from "@kit.CoreFileKit";
21
+ import { fileIo } from '@kit.CoreFileKit';
22
+ import { JSON } from "@kit.ArkTS";
23
+ import cordova from 'libcordova.so';
24
+
25
+ interface OpenFileModel {
26
+ filePath: string
27
+ fileMIMEType: string
28
+ value: boolean
29
+ }
30
+
31
+ export function open(pageIndex: NativeAttribute) {
32
+ let result: OpenFileModel = JSON.parse(pageIndex.pageArgs) as OpenFileModel
33
+ let filePath: string = result.filePath
34
+ let title = filePath.substring(filePath.lastIndexOf('/') + 1)
35
+ let uri = fileUri.getUriFromPath(filePath)
36
+ let fileInfo: filePreview.PreviewInfo = {
37
+ title: title,
38
+ uri: uri,
39
+ mimeType: result.fileMIMEType
40
+ };
41
+ filePreview.openPreview(getContext(), fileInfo).catch((err: BusinessError) => {
42
+ console.error('预览失败:', err.code);
43
+ cordova.onArkTsResult(JSON.stringify({ error: err.message }), pageIndex.pageObject, pageIndex.pageWebTag);
44
+ }).then(() => {
45
+ cordova.onArkTsResult(JSON.stringify({ action: 'open' }), pageIndex.pageObject, pageIndex.pageWebTag);
46
+ })
47
+ }
48
+
49
+ export async function showOpenWithDialog(pageIndex: NativeAttribute) {
50
+ let result: OpenFileModel = JSON.parse(pageIndex.pageArgs) as OpenFileModel
51
+ let context = getContext() as common.UIAbilityContext;
52
+ // result.filePath = context.filesDir+"/sample.txt"
53
+ if (fileExists(result.filePath, pageIndex)) {
54
+ let uri = fileUri.getUriFromPath(result.filePath)
55
+ let want: Want = {
56
+ uri: uri,
57
+ action: 'ohos.want.action.viewData',
58
+ parameters: {
59
+ 'ohos.ability.params.showDefaultPicker': true,
60
+ },
61
+ };
62
+ context.startAbility(want, {
63
+ windowMode: 102
64
+ }).catch((error: BusinessError) => {
65
+ console.log('showOpenWithDialog error==' + error.message)
66
+ cordova.onArkTsResult(JSON.stringify({ error: error.message }), pageIndex.pageObject, pageIndex.pageWebTag);
67
+ }).then(() => {
68
+ cordova.onArkTsResult(JSON.stringify({ action: 'showOpenWithDialog' }), pageIndex.pageObject,
69
+ pageIndex.pageWebTag);
70
+ })
71
+ }
72
+ }
73
+
74
+ function fileExists(filePath: string, pageIndex: NativeAttribute): boolean {
75
+ try {
76
+ fileIo.statSync(filePath)
77
+ return true
78
+ } catch (error) {
79
+ const err = error as BusinessError
80
+ cordova.onArkTsResult(JSON.stringify({ error: err.message }), pageIndex.pageObject, pageIndex.pageWebTag);
81
+ return false
82
+ }
83
+ }
84
+
85
+ export function appIsInstalled(pageIndex: NativeAttribute) {
86
+ let targetUri = pageIndex.pageArgs
87
+ try {
88
+ let result = bundleManager.canOpenLink(targetUri);
89
+ cordova.onArkTsResult(JSON.stringify({ action: 'appIsInstalled', canOpen: result }), pageIndex.pageObject,
90
+ pageIndex.pageWebTag);
91
+ } catch (err) {
92
+ const error = err as BusinessError
93
+ cordova.onArkTsResult(JSON.stringify({ error: error.message }), pageIndex.pageObject, pageIndex.pageWebTag);
94
+ }
95
+ }
96
+
97
+ export async function uninstall(pageIndex: NativeAttribute) {
98
+ let bundleName = pageIndex.pageArgs
99
+ let context = getContext() as common.UIAbilityContext;
100
+ const intent: Want = {
101
+ bundleName: 'com.huawei.hmos.settings',
102
+ abilityName: "com.huawei.hmos.settings.MainAbility",
103
+ uri: 'application_info_entry',
104
+ parameters: {
105
+ "settingsParamBundleName": bundleName,
106
+ }
107
+ };
108
+ context.startAbility(intent).catch((error: BusinessError) => {
109
+ cordova.onArkTsResult(JSON.stringify({ error: error.message }), pageIndex.pageObject, pageIndex.pageWebTag);
110
+ }).then(() => {
111
+ cordova.onArkTsResult(JSON.stringify({ action: 'uninstall' }), pageIndex.pageObject, pageIndex.pageWebTag);
112
+ })
113
+ }
@@ -0,0 +1,51 @@
1
+ cordova.define("cordova-plugin-file-opener2.FileOpener2", function(require, exports, module) {
2
+ /*
3
+ *
4
+ * Licensed to the Apache Software Foundation (ASF) under one
5
+ * or more contributor license agreements. See the NOTICE file
6
+ * distributed with this work for additional information
7
+ * regarding copyright ownership. The ASF licenses this file
8
+ * to you under the Apache License, Version 2.0 (the
9
+ * "License"); you may not use this file except in compliance
10
+ * with the License. You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing,
15
+ * software distributed under the License is distributed on an
16
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
+ * KIND, either express or implied. See the License for the
18
+ * specific language governing permissions and limitations
19
+ * under the License.
20
+ *
21
+ */
22
+
23
+ var exec = require('cordova/exec');
24
+
25
+ function FileOpener2() {}
26
+
27
+ FileOpener2.prototype.open = function (fileName, contentType, callbackContext) {
28
+ contentType = contentType || '';
29
+ callbackContext = callbackContext || {};
30
+ exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType]);
31
+ };
32
+
33
+ FileOpener2.prototype.showOpenWithDialog = function (fileName, contentType, callbackContext) {
34
+ contentType = contentType || '';
35
+ callbackContext = callbackContext || {};
36
+ exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, false, callbackContext.position || [0, 0]]);
37
+ };
38
+
39
+ FileOpener2.prototype.uninstall = function (packageId, callbackContext) {
40
+ callbackContext = callbackContext || {};
41
+ exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'uninstall', [packageId]);
42
+ };
43
+
44
+ FileOpener2.prototype.appIsInstalled = function (packageId, callbackContext) {
45
+ callbackContext = callbackContext || {};
46
+ exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'appIsInstalled', [packageId]);
47
+ };
48
+
49
+ module.exports = new FileOpener2();
50
+
51
+ });