@simplysm/capacitor-plugin-intent 14.0.1 → 14.0.4
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/README.md +133 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# @simplysm/capacitor-plugin-intent
|
|
2
|
+
|
|
3
|
+
Capacitor Intent plugin for Android broadcast communication and activity results.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @simplysm/capacitor-plugin-intent
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## API Overview
|
|
12
|
+
|
|
13
|
+
### Intent
|
|
14
|
+
|
|
15
|
+
| API | Type | Description |
|
|
16
|
+
|-----|------|-------------|
|
|
17
|
+
| `IntentResult` | Interface | Data received from a broadcast or launch intent |
|
|
18
|
+
| `StartActivityForResultOptions` | Interface | Options for starting an Android activity and awaiting its result |
|
|
19
|
+
| `StartActivityForResultResult` | Interface | Result returned from a started activity |
|
|
20
|
+
| `IntentPlugin` | Interface | Native plugin interface for intent operations |
|
|
21
|
+
| `Intent` | Class | Static API for broadcast send/receive, launch intents, and activity results |
|
|
22
|
+
|
|
23
|
+
## Interfaces
|
|
24
|
+
|
|
25
|
+
### IntentResult
|
|
26
|
+
|
|
27
|
+
Data received from a broadcast or launch intent.
|
|
28
|
+
|
|
29
|
+
| Field | Type | Description |
|
|
30
|
+
|-------|------|-------------|
|
|
31
|
+
| `action` | `string \| undefined` | The intent action string (e.g. `"com.example.SCAN_RESULT"`) |
|
|
32
|
+
| `extras` | `Record<string, unknown> \| undefined` | Key-value map of intent extras |
|
|
33
|
+
|
|
34
|
+
### StartActivityForResultOptions
|
|
35
|
+
|
|
36
|
+
Options for launching an Android activity and awaiting its result.
|
|
37
|
+
|
|
38
|
+
| Field | Type | Description |
|
|
39
|
+
|-------|------|-------------|
|
|
40
|
+
| `action` | `string \| undefined` | Intent action (e.g. `"android.intent.action.VIEW"`) |
|
|
41
|
+
| `uri` | `string \| undefined` | Data URI to pass to the intent |
|
|
42
|
+
| `extras` | `Record<string, unknown> \| undefined` | Extra key-value pairs to include |
|
|
43
|
+
| `type` | `string \| undefined` | MIME type (e.g. `"image/*"`) |
|
|
44
|
+
| `packageName` | `string \| undefined` | Target package name for an explicit intent |
|
|
45
|
+
| `className` | `string \| undefined` | Target class name for an explicit intent |
|
|
46
|
+
| `flags` | `number \| undefined` | Intent flags bitmask |
|
|
47
|
+
|
|
48
|
+
### StartActivityForResultResult
|
|
49
|
+
|
|
50
|
+
Result returned when a launched activity finishes.
|
|
51
|
+
|
|
52
|
+
| Field | Type | Description |
|
|
53
|
+
|-------|------|-------------|
|
|
54
|
+
| `resultCode` | `number` | Android result code (`RESULT_OK = -1`, `RESULT_CANCELED = 0`) |
|
|
55
|
+
| `data` | `{ action?: string; uri?: string; extras?: Record<string, unknown> } \| undefined` | Optional data returned by the activity, including its action, URI, and extras |
|
|
56
|
+
|
|
57
|
+
### IntentPlugin
|
|
58
|
+
|
|
59
|
+
Native plugin interface for intent operations.
|
|
60
|
+
|
|
61
|
+
| Method | Signature | Description |
|
|
62
|
+
|--------|-----------|-------------|
|
|
63
|
+
| `subscribe` | `(options: { filters: string[] }, callback: (result: IntentResult) => void) => Promise<{ id: string }>` | Register a broadcast receiver for the given action filters |
|
|
64
|
+
| `unsubscribe` | `(options: { id: string }) => Promise<void>` | Unregister a broadcast receiver by subscription ID |
|
|
65
|
+
| `unsubscribeAll` | `() => Promise<void>` | Unregister all broadcast receivers |
|
|
66
|
+
| `send` | `(options: { action: string; extras?: Record<string, unknown> }) => Promise<void>` | Send a broadcast intent |
|
|
67
|
+
| `getLaunchIntent` | `() => Promise<IntentResult>` | Get the intent that launched the current activity |
|
|
68
|
+
| `addListener` | `(eventName: "newIntent", listenerFunc: (data: IntentResult) => void) => Promise<PluginListenerHandle>` | Listen for new intents delivered to the activity |
|
|
69
|
+
| `removeAllListeners` | `() => Promise<void>` | Remove all event listeners |
|
|
70
|
+
| `startActivityForResult` | `(options: StartActivityForResultOptions) => Promise<StartActivityForResultResult>` | Start an activity and await its result |
|
|
71
|
+
|
|
72
|
+
## Classes
|
|
73
|
+
|
|
74
|
+
### Intent
|
|
75
|
+
|
|
76
|
+
Android Intent plugin for broadcast send/receive and launch intent handling. Designed for industrial devices such as barcode scanners and PDAs.
|
|
77
|
+
|
|
78
|
+
All methods are static.
|
|
79
|
+
|
|
80
|
+
| Method | Signature | Description |
|
|
81
|
+
|--------|-----------|-------------|
|
|
82
|
+
| `subscribe` | `static async subscribe(filters: string[], callback: (result: IntentResult) => void): Promise<() => Promise<void>>` | Register a broadcast receiver for the given action filters. Returns an async unsubscribe function. |
|
|
83
|
+
| `unsubscribeAll` | `static async unsubscribeAll(): Promise<void>` | Unregister all active broadcast receivers |
|
|
84
|
+
| `send` | `static async send(options: { action: string; extras?: Record<string, unknown> }): Promise<void>` | Send a broadcast intent with the specified action and optional extras |
|
|
85
|
+
| `getLaunchIntent` | `static async getLaunchIntent(): Promise<IntentResult>` | Retrieve the intent that launched the current activity |
|
|
86
|
+
| `addListener` | `static async addListener(eventName: "newIntent", callback: (result: IntentResult) => void): Promise<PluginListenerHandle>` | Add a listener for new intents delivered to the activity via `onNewIntent` |
|
|
87
|
+
| `removeAllListeners` | `static async removeAllListeners(): Promise<void>` | Remove all registered event listeners |
|
|
88
|
+
| `startActivityForResult` | `static async startActivityForResult(options: StartActivityForResultOptions): Promise<StartActivityForResultResult>` | Start an Android activity and return its result when it finishes |
|
|
89
|
+
|
|
90
|
+
## Usage Examples
|
|
91
|
+
|
|
92
|
+
### Subscribe to barcode scanner broadcasts
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { Intent } from "@simplysm/capacitor-plugin-intent";
|
|
96
|
+
|
|
97
|
+
const unsubscribe = await Intent.subscribe(
|
|
98
|
+
["com.example.scanner.BARCODE_RESULT"],
|
|
99
|
+
(result) => {
|
|
100
|
+
const barcode = result.extras?.["barcode"] as string;
|
|
101
|
+
handleBarcode(barcode);
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// Later, stop listening
|
|
106
|
+
await unsubscribe();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Send a broadcast
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { Intent } from "@simplysm/capacitor-plugin-intent";
|
|
113
|
+
|
|
114
|
+
await Intent.send({
|
|
115
|
+
action: "com.example.ACTION_TRIGGER_SCAN",
|
|
116
|
+
extras: { mode: "continuous" },
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Start an activity for result
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { Intent } from "@simplysm/capacitor-plugin-intent";
|
|
124
|
+
|
|
125
|
+
const result = await Intent.startActivityForResult({
|
|
126
|
+
action: "android.intent.action.PICK",
|
|
127
|
+
type: "image/*",
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
if (result.resultCode === -1 && result.data?.uri) {
|
|
131
|
+
loadImage(result.data.uri);
|
|
132
|
+
}
|
|
133
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/capacitor-plugin-intent",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.4",
|
|
4
4
|
"description": "심플리즘 패키지 - Capacitor Intent 플러그인",
|
|
5
5
|
"author": "심플리즘",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"android"
|
|
19
19
|
],
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@capacitor/core": "^7.6.
|
|
21
|
+
"@capacitor/core": "^7.6.1"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@capacitor/core": "^7"
|