@capawesome/capacitor-app-launcher 0.0.1
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/CapawesomeCapacitorAppLauncher.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +218 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applauncher/AppLauncher.java +79 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applauncher/AppLauncherPlugin.java +98 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applauncher/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applauncher/classes/CustomExceptions.java +6 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applauncher/classes/options/CanOpenUrlOptions.java +24 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applauncher/classes/options/OpenUrlOptions.java +24 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applauncher/classes/results/CanOpenUrlResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applauncher/classes/results/OpenUrlResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applauncher/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applauncher/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applauncher/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +184 -0
- package/dist/esm/definitions.d.ts +83 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +6 -0
- package/dist/esm/web.js +11 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +25 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +28 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/AppLauncher.swift +32 -0
- package/ios/Plugin/AppLauncherPlugin.swift +63 -0
- package/ios/Plugin/Classes/Options/CanOpenUrlOptions.swift +13 -0
- package/ios/Plugin/Classes/Options/OpenUrlOptions.swift +13 -0
- package/ios/Plugin/Classes/Results/CanOpenUrlResult.swift +16 -0
- package/ios/Plugin/Classes/Results/OpenUrlResult.swift +16 -0
- package/ios/Plugin/Enums/CustomError.swift +21 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +93 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapawesomeCapacitorAppLauncher'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robin Genz
|
|
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 all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapawesomeCapacitorAppLauncher",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapawesomeCapacitorAppLauncher",
|
|
10
|
+
targets: ["AppLauncherPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "AppLauncherPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Plugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "AppLauncherPluginTests",
|
|
25
|
+
dependencies: ["AppLauncherPlugin"],
|
|
26
|
+
path: "ios/PluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Capacitor App Launcher Plugin
|
|
2
|
+
|
|
3
|
+
Capacitor plugin to check if an app can be opened and to open it.
|
|
4
|
+
|
|
5
|
+
<div class="capawesome-z29o10a">
|
|
6
|
+
<a href="https://cloud.capawesome.io/" target="_blank">
|
|
7
|
+
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
|
|
8
|
+
</a>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- 🔗 **Open apps**: Open another app by its URL scheme or package name.
|
|
14
|
+
- ✅ **Availability**: Check whether an app can be opened before trying to open it.
|
|
15
|
+
- 🤖 **Package names**: Check and open apps by their package name on Android.
|
|
16
|
+
- 🔒 **App Store safe**: Uses only official platform APIs.
|
|
17
|
+
- 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
|
|
18
|
+
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
19
|
+
- 🤝 **Compatibility**: Works alongside the [Maps Launcher](https://capawesome.io/docs/sdks/capacitor/maps-launcher/) and [Settings Launcher](https://capawesome.io/docs/sdks/capacitor/settings-launcher/) plugins.
|
|
20
|
+
|
|
21
|
+
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
22
|
+
|
|
23
|
+
## Newsletter
|
|
24
|
+
|
|
25
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
26
|
+
|
|
27
|
+
## Compatibility
|
|
28
|
+
|
|
29
|
+
| Plugin Version | Capacitor Version | Status |
|
|
30
|
+
| -------------- | ----------------- | -------------- |
|
|
31
|
+
| 0.x.x | >=8.x.x | Active support |
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
36
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then use the following prompt:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-app-launcher` plugin in my project.
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install @capawesome/capacitor-app-launcher
|
|
52
|
+
npx cap sync
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Android
|
|
56
|
+
|
|
57
|
+
Starting with Android 11 (API level 30), apps must declare the packages and URL schemes they want to check or open in the [`<queries>`](https://developer.android.com/training/package-visibility) element of their `AndroidManifest.xml`.
|
|
58
|
+
|
|
59
|
+
**If you do not add the corresponding `<queries>` entries, `canOpenUrl(...)` always resolves with `value: false` and `openUrl(...)` may resolve with `completed: false`.**
|
|
60
|
+
|
|
61
|
+
Add an entry for **every** package name and URL scheme you pass to the plugin. For example, to check and open the Gmail app (package name `com.google.android.gm`) and any `mailto:` URL, add the following to your `android/app/src/main/AndroidManifest.xml` before or after the `application` tag:
|
|
62
|
+
|
|
63
|
+
```xml
|
|
64
|
+
<queries>
|
|
65
|
+
<!-- Required to check and open a specific package name. -->
|
|
66
|
+
<package android:name="com.google.android.gm" />
|
|
67
|
+
<!-- Required to check and open a specific URL scheme. -->
|
|
68
|
+
<intent>
|
|
69
|
+
<action android:name="android.intent.action.VIEW" />
|
|
70
|
+
<data android:scheme="mailto" />
|
|
71
|
+
</intent>
|
|
72
|
+
</queries>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### iOS
|
|
76
|
+
|
|
77
|
+
On iOS, every URL scheme you want to check with `canOpenUrl(...)` must be declared in the [`LSApplicationQueriesSchemes`](https://developer.apple.com/documentation/bundleresources/information_property_list/lsapplicationqueriesschemes) key of your app's `Info.plist`.
|
|
78
|
+
|
|
79
|
+
**If you do not add the corresponding entries, `canOpenUrl(...)` always resolves with `value: false`.**
|
|
80
|
+
|
|
81
|
+
Add an entry for **every** URL scheme you pass to the plugin. For example, to check any `mailto:` URL, add the following to your `ios/App/App/Info.plist`:
|
|
82
|
+
|
|
83
|
+
```xml
|
|
84
|
+
<key>LSApplicationQueriesSchemes</key>
|
|
85
|
+
<array>
|
|
86
|
+
<string>mailto</string>
|
|
87
|
+
</array>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Configuration
|
|
91
|
+
|
|
92
|
+
No configuration required for this plugin.
|
|
93
|
+
|
|
94
|
+
## Usage
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { AppLauncher } from '@capawesome/capacitor-app-launcher';
|
|
98
|
+
|
|
99
|
+
const canOpenUrl = async () => {
|
|
100
|
+
const { value } = await AppLauncher.canOpenUrl({ url: 'mailto:' });
|
|
101
|
+
return value;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const openUrl = async () => {
|
|
105
|
+
const { completed } = await AppLauncher.openUrl({ url: 'mailto:' });
|
|
106
|
+
return completed;
|
|
107
|
+
};
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## API
|
|
111
|
+
|
|
112
|
+
<docgen-index>
|
|
113
|
+
|
|
114
|
+
* [`canOpenUrl(...)`](#canopenurl)
|
|
115
|
+
* [`openUrl(...)`](#openurl)
|
|
116
|
+
* [Interfaces](#interfaces)
|
|
117
|
+
|
|
118
|
+
</docgen-index>
|
|
119
|
+
|
|
120
|
+
<docgen-api>
|
|
121
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
122
|
+
|
|
123
|
+
### canOpenUrl(...)
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
canOpenUrl(options: CanOpenUrlOptions) => Promise<CanOpenUrlResult>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Check if an app can be opened with the given URL.
|
|
130
|
+
|
|
131
|
+
On **iOS**, every URL scheme you want to check must be declared in the
|
|
132
|
+
`LSApplicationQueriesSchemes` key of your app's `Info.plist`. Otherwise
|
|
133
|
+
this method always resolves with `value: false`.
|
|
134
|
+
|
|
135
|
+
On **Android**, every package name or URL scheme you want to check must be
|
|
136
|
+
declared in the `<queries>` element of your app's `AndroidManifest.xml`.
|
|
137
|
+
Otherwise this method always resolves with `value: false`.
|
|
138
|
+
|
|
139
|
+
| Param | Type |
|
|
140
|
+
| ------------- | --------------------------------------------------------------- |
|
|
141
|
+
| **`options`** | <code><a href="#canopenurloptions">CanOpenUrlOptions</a></code> |
|
|
142
|
+
|
|
143
|
+
**Returns:** <code>Promise<<a href="#canopenurlresult">CanOpenUrlResult</a>></code>
|
|
144
|
+
|
|
145
|
+
**Since:** 0.1.0
|
|
146
|
+
|
|
147
|
+
--------------------
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
### openUrl(...)
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
openUrl(options: OpenUrlOptions) => Promise<OpenUrlResult>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Open an app with the given URL.
|
|
157
|
+
|
|
158
|
+
| Param | Type |
|
|
159
|
+
| ------------- | --------------------------------------------------------- |
|
|
160
|
+
| **`options`** | <code><a href="#openurloptions">OpenUrlOptions</a></code> |
|
|
161
|
+
|
|
162
|
+
**Returns:** <code>Promise<<a href="#openurlresult">OpenUrlResult</a>></code>
|
|
163
|
+
|
|
164
|
+
**Since:** 0.1.0
|
|
165
|
+
|
|
166
|
+
--------------------
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
### Interfaces
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
#### CanOpenUrlResult
|
|
173
|
+
|
|
174
|
+
| Prop | Type | Description | Since |
|
|
175
|
+
| ----------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
|
|
176
|
+
| **`value`** | <code>boolean</code> | Whether or not the app can be opened with the given URL. On the web, this is always `true` because the browser cannot determine whether a URL can be opened. | 0.1.0 |
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
#### CanOpenUrlOptions
|
|
180
|
+
|
|
181
|
+
| Prop | Type | Description | Since |
|
|
182
|
+
| --------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
183
|
+
| **`url`** | <code>string</code> | The URL to check. On **iOS**, this must be a URL scheme (e.g. `mailto:`). On **Android**, this can be a URL scheme (e.g. `mailto:`) or a package name (e.g. `com.google.android.gm`). | 0.1.0 |
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
#### OpenUrlResult
|
|
187
|
+
|
|
188
|
+
| Prop | Type | Description | Since |
|
|
189
|
+
| --------------- | -------------------- | ----------------------------------------------- | ----- |
|
|
190
|
+
| **`completed`** | <code>boolean</code> | Whether or not the app was opened successfully. | 0.1.0 |
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
#### OpenUrlOptions
|
|
194
|
+
|
|
195
|
+
| Prop | Type | Description | Since |
|
|
196
|
+
| --------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
|
|
197
|
+
| **`url`** | <code>string</code> | The URL to open. On **iOS**, this must be a URL scheme (e.g. `mailto:`). On **Android**, this can be a URL scheme (e.g. `mailto:`) or a package name (e.g. `com.google.android.gm`). | 0.1.0 |
|
|
198
|
+
|
|
199
|
+
</docgen-api>
|
|
200
|
+
|
|
201
|
+
## Migrating from `@capacitor/app-launcher`
|
|
202
|
+
|
|
203
|
+
This plugin is a drop-in replacement for the official `@capacitor/app-launcher` plugin. The API is identical, so you only need to change the import and installation.
|
|
204
|
+
|
|
205
|
+
| `@capacitor/app-launcher` | App Launcher |
|
|
206
|
+
| -------------------------------------------- | -------------------------------------------- |
|
|
207
|
+
| `AppLauncher.canOpenUrl({ url })` | `AppLauncher.canOpenUrl({ url })` |
|
|
208
|
+
| `AppLauncher.openUrl({ url })` | `AppLauncher.openUrl({ url })` |
|
|
209
|
+
|
|
210
|
+
On Android, the `url` may be a URL scheme or a package name for both `canOpenUrl(...)` and `openUrl(...)`.
|
|
211
|
+
|
|
212
|
+
## Changelog
|
|
213
|
+
|
|
214
|
+
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/app-launcher/CHANGELOG.md).
|
|
215
|
+
|
|
216
|
+
## License
|
|
217
|
+
|
|
218
|
+
See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/app-launcher/LICENSE).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace = "io.capawesome.capacitorjs.plugins.applauncher"
|
|
22
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError = false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.applauncher;
|
|
2
|
+
|
|
3
|
+
import android.content.ActivityNotFoundException;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.content.pm.PackageManager;
|
|
7
|
+
import android.content.pm.ResolveInfo;
|
|
8
|
+
import android.net.Uri;
|
|
9
|
+
import androidx.annotation.NonNull;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.applauncher.classes.options.CanOpenUrlOptions;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.applauncher.classes.options.OpenUrlOptions;
|
|
12
|
+
import io.capawesome.capacitorjs.plugins.applauncher.classes.results.CanOpenUrlResult;
|
|
13
|
+
import io.capawesome.capacitorjs.plugins.applauncher.classes.results.OpenUrlResult;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.applauncher.interfaces.NonEmptyResultCallback;
|
|
15
|
+
|
|
16
|
+
public class AppLauncher {
|
|
17
|
+
|
|
18
|
+
@NonNull
|
|
19
|
+
private final AppLauncherPlugin plugin;
|
|
20
|
+
|
|
21
|
+
public AppLauncher(@NonNull AppLauncherPlugin plugin) {
|
|
22
|
+
this.plugin = plugin;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public void canOpenUrl(@NonNull CanOpenUrlOptions options, @NonNull NonEmptyResultCallback<CanOpenUrlResult> callback) {
|
|
26
|
+
boolean value = canOpenUrl(options.getUrl());
|
|
27
|
+
callback.success(new CanOpenUrlResult(value));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public void openUrl(@NonNull OpenUrlOptions options, @NonNull NonEmptyResultCallback<OpenUrlResult> callback) {
|
|
31
|
+
boolean completed = openUrl(options.getUrl());
|
|
32
|
+
callback.success(new OpenUrlResult(completed));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private boolean canOpenUrl(@NonNull String url) {
|
|
36
|
+
if (isPackageInstalled(url)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
|
40
|
+
ResolveInfo resolveInfo = getContext().getPackageManager().resolveActivity(intent, 0);
|
|
41
|
+
return resolveInfo != null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@NonNull
|
|
45
|
+
private Context getContext() {
|
|
46
|
+
return plugin.getContext();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private boolean isPackageInstalled(@NonNull String packageName) {
|
|
50
|
+
try {
|
|
51
|
+
getContext().getPackageManager().getPackageInfo(packageName, 0);
|
|
52
|
+
return true;
|
|
53
|
+
} catch (PackageManager.NameNotFoundException exception) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private boolean openUrl(@NonNull String url) {
|
|
59
|
+
Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
|
60
|
+
viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
61
|
+
try {
|
|
62
|
+
getContext().startActivity(viewIntent);
|
|
63
|
+
return true;
|
|
64
|
+
} catch (ActivityNotFoundException exception) {
|
|
65
|
+
// Fall back to launching the app by its package name.
|
|
66
|
+
}
|
|
67
|
+
Intent launchIntent = getContext().getPackageManager().getLaunchIntentForPackage(url);
|
|
68
|
+
if (launchIntent == null) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
72
|
+
try {
|
|
73
|
+
getContext().startActivity(launchIntent);
|
|
74
|
+
return true;
|
|
75
|
+
} catch (ActivityNotFoundException exception) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
package/android/src/main/java/io/capawesome/capacitorjs/plugins/applauncher/AppLauncherPlugin.java
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.applauncher;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.Logger;
|
|
6
|
+
import com.getcapacitor.Plugin;
|
|
7
|
+
import com.getcapacitor.PluginCall;
|
|
8
|
+
import com.getcapacitor.PluginMethod;
|
|
9
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.applauncher.classes.CustomException;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.applauncher.classes.options.CanOpenUrlOptions;
|
|
12
|
+
import io.capawesome.capacitorjs.plugins.applauncher.classes.options.OpenUrlOptions;
|
|
13
|
+
import io.capawesome.capacitorjs.plugins.applauncher.classes.results.CanOpenUrlResult;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.applauncher.classes.results.OpenUrlResult;
|
|
15
|
+
import io.capawesome.capacitorjs.plugins.applauncher.interfaces.NonEmptyResultCallback;
|
|
16
|
+
import io.capawesome.capacitorjs.plugins.applauncher.interfaces.Result;
|
|
17
|
+
|
|
18
|
+
@CapacitorPlugin(name = "AppLauncher")
|
|
19
|
+
public class AppLauncherPlugin extends Plugin {
|
|
20
|
+
|
|
21
|
+
public static final String ERROR_UNKNOWN_ERROR = "An unknown error has occurred.";
|
|
22
|
+
public static final String TAG = "AppLauncherPlugin";
|
|
23
|
+
|
|
24
|
+
private AppLauncher implementation;
|
|
25
|
+
|
|
26
|
+
@Override
|
|
27
|
+
public void load() {
|
|
28
|
+
super.load();
|
|
29
|
+
this.implementation = new AppLauncher(this);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@PluginMethod
|
|
33
|
+
public void canOpenUrl(PluginCall call) {
|
|
34
|
+
try {
|
|
35
|
+
CanOpenUrlOptions options = new CanOpenUrlOptions(call);
|
|
36
|
+
NonEmptyResultCallback<CanOpenUrlResult> callback = new NonEmptyResultCallback<>() {
|
|
37
|
+
@Override
|
|
38
|
+
public void success(@NonNull CanOpenUrlResult result) {
|
|
39
|
+
resolveCall(call, result);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Override
|
|
43
|
+
public void error(Exception exception) {
|
|
44
|
+
rejectCall(call, exception);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
implementation.canOpenUrl(options, callback);
|
|
48
|
+
} catch (Exception exception) {
|
|
49
|
+
rejectCall(call, exception);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@PluginMethod
|
|
54
|
+
public void openUrl(PluginCall call) {
|
|
55
|
+
try {
|
|
56
|
+
OpenUrlOptions options = new OpenUrlOptions(call);
|
|
57
|
+
NonEmptyResultCallback<OpenUrlResult> callback = new NonEmptyResultCallback<>() {
|
|
58
|
+
@Override
|
|
59
|
+
public void success(@NonNull OpenUrlResult result) {
|
|
60
|
+
resolveCall(call, result);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Override
|
|
64
|
+
public void error(Exception exception) {
|
|
65
|
+
rejectCall(call, exception);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
implementation.openUrl(options, callback);
|
|
69
|
+
} catch (Exception exception) {
|
|
70
|
+
rejectCall(call, exception);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
|
|
75
|
+
String message = exception.getMessage();
|
|
76
|
+
if (message == null) {
|
|
77
|
+
message = ERROR_UNKNOWN_ERROR;
|
|
78
|
+
}
|
|
79
|
+
String code = null;
|
|
80
|
+
if (exception instanceof CustomException) {
|
|
81
|
+
code = ((CustomException) exception).getCode();
|
|
82
|
+
}
|
|
83
|
+
Logger.error(TAG, message, exception);
|
|
84
|
+
call.reject(message, code);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private void resolveCall(@NonNull PluginCall call) {
|
|
88
|
+
call.resolve();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
|
|
92
|
+
if (result == null) {
|
|
93
|
+
call.resolve();
|
|
94
|
+
} else {
|
|
95
|
+
call.resolve(result.toJSObject());
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.applauncher.classes;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
public class CustomException extends Exception {
|
|
7
|
+
|
|
8
|
+
@Nullable
|
|
9
|
+
private final String code;
|
|
10
|
+
|
|
11
|
+
public CustomException(@Nullable String code, @NonNull String message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Nullable
|
|
17
|
+
public String getCode() {
|
|
18
|
+
return code;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.applauncher.classes.options;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.PluginCall;
|
|
5
|
+
import io.capawesome.capacitorjs.plugins.applauncher.classes.CustomExceptions;
|
|
6
|
+
|
|
7
|
+
public class CanOpenUrlOptions {
|
|
8
|
+
|
|
9
|
+
@NonNull
|
|
10
|
+
private final String url;
|
|
11
|
+
|
|
12
|
+
public CanOpenUrlOptions(@NonNull PluginCall call) throws Exception {
|
|
13
|
+
String url = call.getString("url");
|
|
14
|
+
if (url == null) {
|
|
15
|
+
throw CustomExceptions.URL_MISSING;
|
|
16
|
+
}
|
|
17
|
+
this.url = url;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@NonNull
|
|
21
|
+
public String getUrl() {
|
|
22
|
+
return url;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.applauncher.classes.options;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.PluginCall;
|
|
5
|
+
import io.capawesome.capacitorjs.plugins.applauncher.classes.CustomExceptions;
|
|
6
|
+
|
|
7
|
+
public class OpenUrlOptions {
|
|
8
|
+
|
|
9
|
+
@NonNull
|
|
10
|
+
private final String url;
|
|
11
|
+
|
|
12
|
+
public OpenUrlOptions(@NonNull PluginCall call) throws Exception {
|
|
13
|
+
String url = call.getString("url");
|
|
14
|
+
if (url == null) {
|
|
15
|
+
throw CustomExceptions.URL_MISSING;
|
|
16
|
+
}
|
|
17
|
+
this.url = url;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@NonNull
|
|
21
|
+
public String getUrl() {
|
|
22
|
+
return url;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.applauncher.classes.results;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import io.capawesome.capacitorjs.plugins.applauncher.interfaces.Result;
|
|
6
|
+
|
|
7
|
+
public class CanOpenUrlResult implements Result {
|
|
8
|
+
|
|
9
|
+
private final boolean value;
|
|
10
|
+
|
|
11
|
+
public CanOpenUrlResult(boolean value) {
|
|
12
|
+
this.value = value;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Override
|
|
16
|
+
@NonNull
|
|
17
|
+
public JSObject toJSObject() {
|
|
18
|
+
JSObject result = new JSObject();
|
|
19
|
+
result.put("value", value);
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.applauncher.classes.results;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import io.capawesome.capacitorjs.plugins.applauncher.interfaces.Result;
|
|
6
|
+
|
|
7
|
+
public class OpenUrlResult implements Result {
|
|
8
|
+
|
|
9
|
+
private final boolean completed;
|
|
10
|
+
|
|
11
|
+
public OpenUrlResult(boolean completed) {
|
|
12
|
+
this.completed = completed;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Override
|
|
16
|
+
@NonNull
|
|
17
|
+
public JSObject toJSObject() {
|
|
18
|
+
JSObject result = new JSObject();
|
|
19
|
+
result.put("completed", completed);
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
}
|