@capawesome/capacitor-android-intent-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/CapawesomeCapacitorAndroidIntentLauncher.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +242 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/androidintentlauncher/AndroidIntentLauncher.java +106 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/androidintentlauncher/AndroidIntentLauncherPlugin.java +103 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/androidintentlauncher/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/androidintentlauncher/classes/CustomExceptions.java +11 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/androidintentlauncher/classes/options/IntentOptions.java +110 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/androidintentlauncher/classes/results/CanResolveActivityResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/androidintentlauncher/classes/results/StartActivityResult.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/androidintentlauncher/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/androidintentlauncher/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/androidintentlauncher/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +296 -0
- package/dist/esm/definitions.d.ts +164 -0
- package/dist/esm/definitions.js +19 -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 +10 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +43 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +46 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/AndroidIntentLauncherPlugin.swift +24 -0
- package/ios/Plugin/Info.plist +24 -0
- package/package.json +91 -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 = 'CapawesomeCapacitorAndroidIntentLauncher'
|
|
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: "CapawesomeCapacitorAndroidIntentLauncher",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapawesomeCapacitorAndroidIntentLauncher",
|
|
10
|
+
targets: ["AndroidIntentLauncherPlugin"])
|
|
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: "AndroidIntentLauncherPlugin",
|
|
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: "AndroidIntentLauncherPluginTests",
|
|
25
|
+
dependencies: ["AndroidIntentLauncherPlugin"],
|
|
26
|
+
path: "ios/PluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# Capacitor Android Intent Launcher Plugin
|
|
2
|
+
|
|
3
|
+
Capacitor plugin to launch arbitrary Android intents.
|
|
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
|
+
- 🚀 **Start activities**: Launch any Android activity via a custom intent and read its result.
|
|
14
|
+
- 🔍 **Resolve activities**: Check whether an activity can handle an intent before launching it.
|
|
15
|
+
- 🎯 **Explicit & implicit intents**: Target a specific component or let the system pick a handler.
|
|
16
|
+
- 📦 **Extras & flags**: Attach primitive extras and intent flags.
|
|
17
|
+
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
18
|
+
- 🤝 **Compatibility**: Works alongside the [Settings Launcher](https://capawesome.io/docs/sdks/capacitor/settings-launcher/) and [App Launcher](https://capawesome.io/docs/sdks/capacitor/app-launcher/) plugins.
|
|
19
|
+
|
|
20
|
+
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
21
|
+
|
|
22
|
+
## Newsletter
|
|
23
|
+
|
|
24
|
+
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/).
|
|
25
|
+
|
|
26
|
+
## Compatibility
|
|
27
|
+
|
|
28
|
+
| Plugin Version | Capacitor Version | Status |
|
|
29
|
+
| -------------- | ----------------- | -------------- |
|
|
30
|
+
| 0.x.x | >=8.x.x | Active support |
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
35
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then use the following prompt:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-android-intent-launcher` plugin in my project.
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install @capawesome/capacitor-android-intent-launcher
|
|
51
|
+
npx cap sync
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
This plugin is only available on **Android**. On iOS and Web, all methods reject as unimplemented.
|
|
55
|
+
|
|
56
|
+
### Android
|
|
57
|
+
|
|
58
|
+
No additional configuration is required for this plugin.
|
|
59
|
+
|
|
60
|
+
However, on Android 11 (API level 30) and higher, [package visibility](https://developer.android.com/training/package-visibility) restricts which apps and intents your app can see. To launch or resolve intents that target other apps, you may need to declare matching [`<queries>`](https://developer.android.com/guide/topics/manifest/queries-element) entries in your app's `AndroidManifest.xml`. See [Package visibility](#package-visibility) below.
|
|
61
|
+
|
|
62
|
+
### iOS
|
|
63
|
+
|
|
64
|
+
This plugin has **no iOS implementation**. Intents are an Android-only concept. All methods reject as unimplemented on iOS.
|
|
65
|
+
|
|
66
|
+
## Configuration
|
|
67
|
+
|
|
68
|
+
No configuration required for this plugin.
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { AndroidIntentLauncher } from '@capawesome/capacitor-android-intent-launcher';
|
|
74
|
+
|
|
75
|
+
const startActivity = async () => {
|
|
76
|
+
const { resultCode } = await AndroidIntentLauncher.startActivity({
|
|
77
|
+
action: 'android.intent.action.VIEW',
|
|
78
|
+
dataUri: 'https://capawesome.io',
|
|
79
|
+
});
|
|
80
|
+
return resultCode;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const canResolveActivity = async () => {
|
|
84
|
+
const { canResolve } = await AndroidIntentLauncher.canResolveActivity({
|
|
85
|
+
action: 'android.intent.action.VIEW',
|
|
86
|
+
dataUri: 'https://capawesome.io',
|
|
87
|
+
});
|
|
88
|
+
return canResolve;
|
|
89
|
+
};
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## API
|
|
93
|
+
|
|
94
|
+
<docgen-index>
|
|
95
|
+
|
|
96
|
+
* [`canResolveActivity(...)`](#canresolveactivity)
|
|
97
|
+
* [`startActivity(...)`](#startactivity)
|
|
98
|
+
* [Interfaces](#interfaces)
|
|
99
|
+
* [Type Aliases](#type-aliases)
|
|
100
|
+
|
|
101
|
+
</docgen-index>
|
|
102
|
+
|
|
103
|
+
<docgen-api>
|
|
104
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
105
|
+
|
|
106
|
+
### canResolveActivity(...)
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
canResolveActivity(options: CanResolveActivityOptions) => Promise<CanResolveActivityResult>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Check whether an activity exists that can handle the given intent.
|
|
113
|
+
|
|
114
|
+
This is a wrapper around the `PackageManager.resolveActivity(...)` API.
|
|
115
|
+
|
|
116
|
+
On Android 11 (API level 30) and higher, the result is affected by
|
|
117
|
+
package visibility. Your app may need to declare matching `<queries>`
|
|
118
|
+
entries in its `AndroidManifest.xml` for the intent to be resolved.
|
|
119
|
+
|
|
120
|
+
Only available on Android.
|
|
121
|
+
|
|
122
|
+
| Param | Type |
|
|
123
|
+
| ------------- | --------------------------------------------------------------------- |
|
|
124
|
+
| **`options`** | <code><a href="#startactivityoptions">StartActivityOptions</a></code> |
|
|
125
|
+
|
|
126
|
+
**Returns:** <code>Promise<<a href="#canresolveactivityresult">CanResolveActivityResult</a>></code>
|
|
127
|
+
|
|
128
|
+
**Since:** 0.1.0
|
|
129
|
+
|
|
130
|
+
--------------------
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
### startActivity(...)
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
startActivity(options: StartActivityOptions) => Promise<StartActivityResult>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Launch an activity for the given intent.
|
|
140
|
+
|
|
141
|
+
The intent is started via the `startActivityForResult(...)` API so the
|
|
142
|
+
result code and result data of the launched activity are returned once it
|
|
143
|
+
finishes.
|
|
144
|
+
|
|
145
|
+
This is the power-user escape hatch for system screens and app
|
|
146
|
+
integrations that no dedicated plugin covers. Prefer a typed plugin (such
|
|
147
|
+
as [Settings Launcher](https://capawesome.io/docs/sdks/capacitor/settings-launcher/)
|
|
148
|
+
or [App Launcher](https://capawesome.io/docs/sdks/capacitor/app-launcher/))
|
|
149
|
+
where one exists.
|
|
150
|
+
|
|
151
|
+
Only available on Android.
|
|
152
|
+
|
|
153
|
+
| Param | Type |
|
|
154
|
+
| ------------- | --------------------------------------------------------------------- |
|
|
155
|
+
| **`options`** | <code><a href="#startactivityoptions">StartActivityOptions</a></code> |
|
|
156
|
+
|
|
157
|
+
**Returns:** <code>Promise<<a href="#startactivityresult">StartActivityResult</a>></code>
|
|
158
|
+
|
|
159
|
+
**Since:** 0.1.0
|
|
160
|
+
|
|
161
|
+
--------------------
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
### Interfaces
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
#### CanResolveActivityResult
|
|
168
|
+
|
|
169
|
+
| Prop | Type | Description | Since |
|
|
170
|
+
| ---------------- | -------------------- | ------------------------------------------------------------- | ----- |
|
|
171
|
+
| **`canResolve`** | <code>boolean</code> | Whether or not an activity exists that can handle the intent. | 0.1.0 |
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
#### StartActivityOptions
|
|
175
|
+
|
|
176
|
+
| Prop | Type | Description | Since |
|
|
177
|
+
| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
|
|
178
|
+
| **`action`** | <code>string</code> | The action of the intent. | 0.1.0 |
|
|
179
|
+
| **`categories`** | <code>string[]</code> | The categories to add to the intent. | 0.1.0 |
|
|
180
|
+
| **`className`** | <code>string</code> | The fully qualified class name of the component to launch. Must be used together with the `packageName` property to create an explicit intent that targets a specific component. | 0.1.0 |
|
|
181
|
+
| **`dataUri`** | <code>string</code> | The data URI of the intent. | 0.1.0 |
|
|
182
|
+
| **`extras`** | <code>{ [key: string]: string \| number \| boolean; }</code> | The extras to add to the intent. Only primitive values (string, number and boolean) are supported. | 0.1.0 |
|
|
183
|
+
| **`flags`** | <code>number</code> | The flags to add to the intent. Multiple flags can be combined using the bitwise OR operator. | 0.1.0 |
|
|
184
|
+
| **`packageName`** | <code>string</code> | The package name of the component to launch. If used without the `className` property, the intent is restricted to the given package. If used together with the `className` property, an explicit intent that targets a specific component is created. | 0.1.0 |
|
|
185
|
+
| **`type`** | <code>string</code> | The MIME type of the intent data. | 0.1.0 |
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
#### StartActivityResult
|
|
189
|
+
|
|
190
|
+
| Prop | Type | Description | Since |
|
|
191
|
+
| ---------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
192
|
+
| **`dataUri`** | <code>string \| null</code> | The data URI returned by the launched activity. | 0.1.0 |
|
|
193
|
+
| **`resultCode`** | <code>number</code> | The result code returned by the launched activity. The value is `-1` if the activity finished successfully (`RESULT_OK`), `0` if it was canceled (`RESULT_CANCELED`) or any other custom result code set by the launched activity. | 0.1.0 |
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
### Type Aliases
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
#### CanResolveActivityOptions
|
|
200
|
+
|
|
201
|
+
<code><a href="#startactivityoptions">StartActivityOptions</a></code>
|
|
202
|
+
|
|
203
|
+
</docgen-api>
|
|
204
|
+
|
|
205
|
+
## Common Intents
|
|
206
|
+
|
|
207
|
+
The following table lists a few common intents to get you started. See the [Android documentation](https://developer.android.com/reference/android/content/Intent) for the full list of actions, categories, extras and flags.
|
|
208
|
+
|
|
209
|
+
| Use case | `action` | `dataUri` | `type` | `extras` |
|
|
210
|
+
| ----------------- | --------------------------------- | ------------------------ | -------------- | ----------------------------------------------------------- |
|
|
211
|
+
| Open a website | `android.intent.action.VIEW` | `https://capawesome.io` | – | – |
|
|
212
|
+
| Open the dialer | `android.intent.action.DIAL` | `tel:+12025550123` | – | – |
|
|
213
|
+
| Compose an email | `android.intent.action.SENDTO` | `mailto:hi@example.com` | – | `{ 'android.intent.extra.SUBJECT': 'Hi' }` |
|
|
214
|
+
| Share plain text | `android.intent.action.SEND` | – | `text/plain` | `{ 'android.intent.extra.TEXT': 'Hello world!' }` |
|
|
215
|
+
| Open app settings | `android.settings.APPLICATION_DETAILS_SETTINGS` | `package:com.example.app` | – | – |
|
|
216
|
+
|
|
217
|
+
This plugin is intended as a **last resort** for system screens and app integrations that no dedicated plugin covers. Prefer a typed plugin where one exists — for example [Settings Launcher](https://capawesome.io/docs/sdks/capacitor/settings-launcher/) for system settings screens or [App Launcher](https://capawesome.io/docs/sdks/capacitor/app-launcher/) for opening URLs and other apps.
|
|
218
|
+
|
|
219
|
+
## Package Visibility
|
|
220
|
+
|
|
221
|
+
On Android 11 (API level 30) and higher, [package visibility](https://developer.android.com/training/package-visibility) limits which other apps your app can interact with. This affects both `startActivity(...)` (an unresolvable intent rejects with the error code `ACTIVITY_NOT_FOUND`) and `canResolveActivity(...)` (which returns `false` for intents your app cannot see).
|
|
222
|
+
|
|
223
|
+
If you launch or resolve intents that target other apps, declare the intents you query in your app's `AndroidManifest.xml`. The plugin cannot predeclare arbitrary intents on your behalf.
|
|
224
|
+
|
|
225
|
+
```xml
|
|
226
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
227
|
+
<queries>
|
|
228
|
+
<intent>
|
|
229
|
+
<action android:name="android.intent.action.VIEW" />
|
|
230
|
+
<data android:scheme="https" />
|
|
231
|
+
</intent>
|
|
232
|
+
</queries>
|
|
233
|
+
</manifest>
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Changelog
|
|
237
|
+
|
|
238
|
+
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/android-intent-launcher/CHANGELOG.md).
|
|
239
|
+
|
|
240
|
+
## License
|
|
241
|
+
|
|
242
|
+
See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/android-intent-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.androidintentlauncher"
|
|
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 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"></manifest>
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.androidintentlauncher;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.content.Intent;
|
|
5
|
+
import android.content.pm.PackageManager;
|
|
6
|
+
import android.net.Uri;
|
|
7
|
+
import androidx.activity.result.ActivityResult;
|
|
8
|
+
import androidx.annotation.NonNull;
|
|
9
|
+
import com.getcapacitor.JSObject;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.androidintentlauncher.classes.options.IntentOptions;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.androidintentlauncher.classes.results.CanResolveActivityResult;
|
|
12
|
+
import io.capawesome.capacitorjs.plugins.androidintentlauncher.classes.results.StartActivityResult;
|
|
13
|
+
import io.capawesome.capacitorjs.plugins.androidintentlauncher.interfaces.NonEmptyResultCallback;
|
|
14
|
+
import java.util.Iterator;
|
|
15
|
+
import java.util.List;
|
|
16
|
+
import org.json.JSONException;
|
|
17
|
+
|
|
18
|
+
public class AndroidIntentLauncher {
|
|
19
|
+
|
|
20
|
+
@NonNull
|
|
21
|
+
private final AndroidIntentLauncherPlugin plugin;
|
|
22
|
+
|
|
23
|
+
public AndroidIntentLauncher(@NonNull AndroidIntentLauncherPlugin plugin) {
|
|
24
|
+
this.plugin = plugin;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public void canResolveActivity(@NonNull IntentOptions options, @NonNull NonEmptyResultCallback<CanResolveActivityResult> callback) {
|
|
28
|
+
Intent intent = createIntent(options);
|
|
29
|
+
PackageManager packageManager = getContext().getPackageManager();
|
|
30
|
+
boolean canResolve = intent.resolveActivity(packageManager) != null;
|
|
31
|
+
callback.success(new CanResolveActivityResult(canResolve));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@NonNull
|
|
35
|
+
public Intent createIntent(@NonNull IntentOptions options) {
|
|
36
|
+
Intent intent = new Intent();
|
|
37
|
+
intent.setAction(options.getAction());
|
|
38
|
+
String dataUri = options.getDataUri();
|
|
39
|
+
String type = options.getType();
|
|
40
|
+
if (dataUri != null && type != null) {
|
|
41
|
+
intent.setDataAndType(Uri.parse(dataUri), type);
|
|
42
|
+
} else if (dataUri != null) {
|
|
43
|
+
intent.setData(Uri.parse(dataUri));
|
|
44
|
+
} else if (type != null) {
|
|
45
|
+
intent.setType(type);
|
|
46
|
+
}
|
|
47
|
+
List<String> categories = options.getCategories();
|
|
48
|
+
if (categories != null) {
|
|
49
|
+
for (String category : categories) {
|
|
50
|
+
intent.addCategory(category);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
String packageName = options.getPackageName();
|
|
54
|
+
String className = options.getClassName();
|
|
55
|
+
if (packageName != null && className != null) {
|
|
56
|
+
intent.setClassName(packageName, className);
|
|
57
|
+
} else if (packageName != null) {
|
|
58
|
+
intent.setPackage(packageName);
|
|
59
|
+
}
|
|
60
|
+
JSObject extras = options.getExtras();
|
|
61
|
+
if (extras != null) {
|
|
62
|
+
applyExtras(intent, extras);
|
|
63
|
+
}
|
|
64
|
+
Integer flags = options.getFlags();
|
|
65
|
+
if (flags != null) {
|
|
66
|
+
intent.setFlags(flags);
|
|
67
|
+
}
|
|
68
|
+
return intent;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@NonNull
|
|
72
|
+
public StartActivityResult createStartActivityResult(@NonNull ActivityResult result) {
|
|
73
|
+
Intent data = result.getData();
|
|
74
|
+
String dataUri = data != null && data.getData() != null ? data.getData().toString() : null;
|
|
75
|
+
return new StartActivityResult(result.getResultCode(), dataUri);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private void applyExtras(@NonNull Intent intent, @NonNull JSObject extras) {
|
|
79
|
+
Iterator<String> keys = extras.keys();
|
|
80
|
+
while (keys.hasNext()) {
|
|
81
|
+
String key = keys.next();
|
|
82
|
+
Object value;
|
|
83
|
+
try {
|
|
84
|
+
value = extras.get(key);
|
|
85
|
+
} catch (JSONException exception) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (value instanceof String) {
|
|
89
|
+
intent.putExtra(key, (String) value);
|
|
90
|
+
} else if (value instanceof Boolean) {
|
|
91
|
+
intent.putExtra(key, (Boolean) value);
|
|
92
|
+
} else if (value instanceof Integer) {
|
|
93
|
+
intent.putExtra(key, (Integer) value);
|
|
94
|
+
} else if (value instanceof Long) {
|
|
95
|
+
intent.putExtra(key, (Long) value);
|
|
96
|
+
} else if (value instanceof Double) {
|
|
97
|
+
intent.putExtra(key, (Double) value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@NonNull
|
|
103
|
+
private Context getContext() {
|
|
104
|
+
return plugin.getContext();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.androidintentlauncher;
|
|
2
|
+
|
|
3
|
+
import android.content.ActivityNotFoundException;
|
|
4
|
+
import android.content.Intent;
|
|
5
|
+
import androidx.activity.result.ActivityResult;
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
|
+
import androidx.annotation.Nullable;
|
|
8
|
+
import com.getcapacitor.Logger;
|
|
9
|
+
import com.getcapacitor.Plugin;
|
|
10
|
+
import com.getcapacitor.PluginCall;
|
|
11
|
+
import com.getcapacitor.PluginMethod;
|
|
12
|
+
import com.getcapacitor.annotation.ActivityCallback;
|
|
13
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.androidintentlauncher.classes.CustomException;
|
|
15
|
+
import io.capawesome.capacitorjs.plugins.androidintentlauncher.classes.CustomExceptions;
|
|
16
|
+
import io.capawesome.capacitorjs.plugins.androidintentlauncher.classes.options.IntentOptions;
|
|
17
|
+
import io.capawesome.capacitorjs.plugins.androidintentlauncher.classes.results.CanResolveActivityResult;
|
|
18
|
+
import io.capawesome.capacitorjs.plugins.androidintentlauncher.interfaces.NonEmptyResultCallback;
|
|
19
|
+
import io.capawesome.capacitorjs.plugins.androidintentlauncher.interfaces.Result;
|
|
20
|
+
|
|
21
|
+
@CapacitorPlugin(name = "AndroidIntentLauncher")
|
|
22
|
+
public class AndroidIntentLauncherPlugin extends Plugin {
|
|
23
|
+
|
|
24
|
+
public static final String ERROR_UNKNOWN_ERROR = "An unknown error occurred.";
|
|
25
|
+
public static final String TAG = "AndroidIntentLauncherPlugin";
|
|
26
|
+
|
|
27
|
+
private AndroidIntentLauncher implementation;
|
|
28
|
+
|
|
29
|
+
@Override
|
|
30
|
+
public void load() {
|
|
31
|
+
implementation = new AndroidIntentLauncher(this);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@PluginMethod
|
|
35
|
+
public void canResolveActivity(PluginCall call) {
|
|
36
|
+
try {
|
|
37
|
+
IntentOptions options = new IntentOptions(call);
|
|
38
|
+
NonEmptyResultCallback<CanResolveActivityResult> callback = new NonEmptyResultCallback<>() {
|
|
39
|
+
@Override
|
|
40
|
+
public void success(@NonNull CanResolveActivityResult result) {
|
|
41
|
+
resolveCall(call, result);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Override
|
|
45
|
+
public void error(@NonNull Exception exception) {
|
|
46
|
+
rejectCall(call, exception);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
implementation.canResolveActivity(options, callback);
|
|
51
|
+
} catch (Exception exception) {
|
|
52
|
+
rejectCall(call, exception);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@PluginMethod
|
|
57
|
+
public void startActivity(PluginCall call) {
|
|
58
|
+
Intent intent;
|
|
59
|
+
try {
|
|
60
|
+
IntentOptions options = new IntentOptions(call);
|
|
61
|
+
intent = implementation.createIntent(options);
|
|
62
|
+
} catch (Exception exception) {
|
|
63
|
+
rejectCall(call, exception);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
startActivityForResult(call, intent, "handleStartActivityResult");
|
|
68
|
+
} catch (ActivityNotFoundException exception) {
|
|
69
|
+
rejectCall(call, CustomExceptions.ACTIVITY_NOT_FOUND);
|
|
70
|
+
} catch (Exception exception) {
|
|
71
|
+
rejectCall(call, CustomExceptions.START_FAILED);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@ActivityCallback
|
|
76
|
+
private void handleStartActivityResult(@Nullable PluginCall call, @NonNull ActivityResult result) {
|
|
77
|
+
if (call == null) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
resolveCall(call, implementation.createStartActivityResult(result));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
|
|
84
|
+
String message = exception.getMessage();
|
|
85
|
+
if (message == null) {
|
|
86
|
+
message = ERROR_UNKNOWN_ERROR;
|
|
87
|
+
}
|
|
88
|
+
String code = null;
|
|
89
|
+
if (exception instanceof CustomException) {
|
|
90
|
+
code = ((CustomException) exception).getCode();
|
|
91
|
+
}
|
|
92
|
+
Logger.error(TAG, message, exception);
|
|
93
|
+
call.reject(message, code);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
|
|
97
|
+
if (result == null) {
|
|
98
|
+
call.resolve();
|
|
99
|
+
} else {
|
|
100
|
+
call.resolve(result.toJSObject());
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.androidintentlauncher.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,11 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.androidintentlauncher.classes;
|
|
2
|
+
|
|
3
|
+
public class CustomExceptions {
|
|
4
|
+
|
|
5
|
+
public static final CustomException ACTION_MISSING = new CustomException(null, "action must be provided.");
|
|
6
|
+
public static final CustomException ACTIVITY_NOT_FOUND = new CustomException(
|
|
7
|
+
"ACTIVITY_NOT_FOUND",
|
|
8
|
+
"No activity was found that can handle the intent."
|
|
9
|
+
);
|
|
10
|
+
public static final CustomException START_FAILED = new CustomException("START_FAILED", "The activity could not be started.");
|
|
11
|
+
}
|