@simplysm/capacitor-plugin-intent 14.0.4 → 14.0.5
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 +108 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# @simplysm/capacitor-plugin-intent
|
|
2
2
|
|
|
3
|
-
Capacitor
|
|
3
|
+
Capacitor plugin for Android intent handling. Supports broadcast send/receive, launch intent retrieval, event listeners for new intents, and `startActivityForResult`. Designed for industrial device integration (barcode scanners, PDA devices, etc.).
|
|
4
|
+
|
|
5
|
+
- **Android**: Full intent support
|
|
6
|
+
- **Browser**: Web fallback for development
|
|
4
7
|
|
|
5
8
|
## Installation
|
|
6
9
|
|
|
@@ -10,7 +13,7 @@ npm install @simplysm/capacitor-plugin-intent
|
|
|
10
13
|
|
|
11
14
|
## API Overview
|
|
12
15
|
|
|
13
|
-
###
|
|
16
|
+
### Interfaces
|
|
14
17
|
|
|
15
18
|
| API | Type | Description |
|
|
16
19
|
|-----|------|-------------|
|
|
@@ -18,23 +21,45 @@ npm install @simplysm/capacitor-plugin-intent
|
|
|
18
21
|
| `StartActivityForResultOptions` | Interface | Options for starting an Android activity and awaiting its result |
|
|
19
22
|
| `StartActivityForResultResult` | Interface | Result returned from a started activity |
|
|
20
23
|
| `IntentPlugin` | Interface | Native plugin interface for intent operations |
|
|
21
|
-
| `Intent` | Class | Static API for broadcast send/receive, launch intents, and activity results |
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
### Classes
|
|
26
|
+
|
|
27
|
+
| API | Type | Description |
|
|
28
|
+
|-----|------|-------------|
|
|
29
|
+
| `Intent` | Class | Static API for broadcast send/receive, launch intents, and activity results |
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
## `IntentResult`
|
|
26
32
|
|
|
27
33
|
Data received from a broadcast or launch intent.
|
|
28
34
|
|
|
35
|
+
```typescript
|
|
36
|
+
interface IntentResult {
|
|
37
|
+
action?: string;
|
|
38
|
+
extras?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
29
42
|
| Field | Type | Description |
|
|
30
43
|
|-------|------|-------------|
|
|
31
44
|
| `action` | `string \| undefined` | The intent action string (e.g. `"com.example.SCAN_RESULT"`) |
|
|
32
45
|
| `extras` | `Record<string, unknown> \| undefined` | Key-value map of intent extras |
|
|
33
46
|
|
|
34
|
-
|
|
47
|
+
## `StartActivityForResultOptions`
|
|
35
48
|
|
|
36
49
|
Options for launching an Android activity and awaiting its result.
|
|
37
50
|
|
|
51
|
+
```typescript
|
|
52
|
+
interface StartActivityForResultOptions {
|
|
53
|
+
action?: string;
|
|
54
|
+
uri?: string;
|
|
55
|
+
extras?: Record<string, unknown>;
|
|
56
|
+
type?: string;
|
|
57
|
+
packageName?: string;
|
|
58
|
+
className?: string;
|
|
59
|
+
flags?: number;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
38
63
|
| Field | Type | Description |
|
|
39
64
|
|-------|------|-------------|
|
|
40
65
|
| `action` | `string \| undefined` | Intent action (e.g. `"android.intent.action.VIEW"`) |
|
|
@@ -42,21 +67,53 @@ Options for launching an Android activity and awaiting its result.
|
|
|
42
67
|
| `extras` | `Record<string, unknown> \| undefined` | Extra key-value pairs to include |
|
|
43
68
|
| `type` | `string \| undefined` | MIME type (e.g. `"image/*"`) |
|
|
44
69
|
| `packageName` | `string \| undefined` | Target package name for an explicit intent |
|
|
45
|
-
| `className` | `string \| undefined` | Target class name for an explicit intent |
|
|
70
|
+
| `className` | `string \| undefined` | Target Activity class name for an explicit intent |
|
|
46
71
|
| `flags` | `number \| undefined` | Intent flags bitmask |
|
|
47
72
|
|
|
48
|
-
|
|
73
|
+
## `StartActivityForResultResult`
|
|
49
74
|
|
|
50
75
|
Result returned when a launched activity finishes.
|
|
51
76
|
|
|
77
|
+
```typescript
|
|
78
|
+
interface StartActivityForResultResult {
|
|
79
|
+
resultCode: number;
|
|
80
|
+
data?: {
|
|
81
|
+
action?: string;
|
|
82
|
+
uri?: string;
|
|
83
|
+
extras?: Record<string, unknown>;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
52
88
|
| Field | Type | Description |
|
|
53
89
|
|-------|------|-------------|
|
|
54
90
|
| `resultCode` | `number` | Android result code (`RESULT_OK = -1`, `RESULT_CANCELED = 0`) |
|
|
55
91
|
| `data` | `{ action?: string; uri?: string; extras?: Record<string, unknown> } \| undefined` | Optional data returned by the activity, including its action, URI, and extras |
|
|
56
92
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
Native plugin interface for intent operations.
|
|
93
|
+
## `IntentPlugin`
|
|
94
|
+
|
|
95
|
+
Native plugin interface for intent operations. Use the `Intent` class for a simplified API.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
interface IntentPlugin {
|
|
99
|
+
subscribe(
|
|
100
|
+
options: { filters: string[] },
|
|
101
|
+
callback: (result: IntentResult) => void,
|
|
102
|
+
): Promise<{ id: string }>;
|
|
103
|
+
unsubscribe(options: { id: string }): Promise<void>;
|
|
104
|
+
unsubscribeAll(): Promise<void>;
|
|
105
|
+
send(options: { action: string; extras?: Record<string, unknown> }): Promise<void>;
|
|
106
|
+
getLaunchIntent(): Promise<IntentResult>;
|
|
107
|
+
addListener(
|
|
108
|
+
eventName: "newIntent",
|
|
109
|
+
listenerFunc: (data: IntentResult) => void,
|
|
110
|
+
): Promise<PluginListenerHandle>;
|
|
111
|
+
removeAllListeners(): Promise<void>;
|
|
112
|
+
startActivityForResult(
|
|
113
|
+
options: StartActivityForResultOptions,
|
|
114
|
+
): Promise<StartActivityForResultResult>;
|
|
115
|
+
}
|
|
116
|
+
```
|
|
60
117
|
|
|
61
118
|
| Method | Signature | Description |
|
|
62
119
|
|--------|-----------|-------------|
|
|
@@ -69,13 +126,29 @@ Native plugin interface for intent operations.
|
|
|
69
126
|
| `removeAllListeners` | `() => Promise<void>` | Remove all event listeners |
|
|
70
127
|
| `startActivityForResult` | `(options: StartActivityForResultOptions) => Promise<StartActivityForResultResult>` | Start an activity and await its result |
|
|
71
128
|
|
|
72
|
-
##
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
129
|
+
## `Intent`
|
|
130
|
+
|
|
131
|
+
Abstract class with static methods for Android intent operations. Designed for industrial devices such as barcode scanners and PDAs.
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
abstract class Intent {
|
|
135
|
+
static async subscribe(
|
|
136
|
+
filters: string[],
|
|
137
|
+
callback: (result: IntentResult) => void,
|
|
138
|
+
): Promise<() => Promise<void>>;
|
|
139
|
+
static async unsubscribeAll(): Promise<void>;
|
|
140
|
+
static async send(options: { action: string; extras?: Record<string, unknown> }): Promise<void>;
|
|
141
|
+
static async getLaunchIntent(): Promise<IntentResult>;
|
|
142
|
+
static async addListener(
|
|
143
|
+
eventName: "newIntent",
|
|
144
|
+
callback: (result: IntentResult) => void,
|
|
145
|
+
): Promise<PluginListenerHandle>;
|
|
146
|
+
static async removeAllListeners(): Promise<void>;
|
|
147
|
+
static async startActivityForResult(
|
|
148
|
+
options: StartActivityForResultOptions,
|
|
149
|
+
): Promise<StartActivityForResultResult>;
|
|
150
|
+
}
|
|
151
|
+
```
|
|
79
152
|
|
|
80
153
|
| Method | Signature | Description |
|
|
81
154
|
|--------|-----------|-------------|
|
|
@@ -83,7 +156,7 @@ All methods are static.
|
|
|
83
156
|
| `unsubscribeAll` | `static async unsubscribeAll(): Promise<void>` | Unregister all active broadcast receivers |
|
|
84
157
|
| `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
158
|
| `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` |
|
|
159
|
+
| `addListener` | `static async addListener(eventName: "newIntent", callback: (result: IntentResult) => void): Promise<PluginListenerHandle>` | Add a listener for new intents delivered to the activity via `onNewIntent`. Call `handle.remove()` to unregister. |
|
|
87
160
|
| `removeAllListeners` | `static async removeAllListeners(): Promise<void>` | Remove all registered event listeners |
|
|
88
161
|
| `startActivityForResult` | `static async startActivityForResult(options: StartActivityForResultOptions): Promise<StartActivityForResultResult>` | Start an Android activity and return its result when it finishes |
|
|
89
162
|
|
|
@@ -91,14 +164,14 @@ All methods are static.
|
|
|
91
164
|
|
|
92
165
|
### Subscribe to barcode scanner broadcasts
|
|
93
166
|
|
|
94
|
-
```
|
|
167
|
+
```typescript
|
|
95
168
|
import { Intent } from "@simplysm/capacitor-plugin-intent";
|
|
96
169
|
|
|
97
170
|
const unsubscribe = await Intent.subscribe(
|
|
98
|
-
["com.
|
|
171
|
+
["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
99
172
|
(result) => {
|
|
100
|
-
const barcode = result.extras?.["
|
|
101
|
-
|
|
173
|
+
const barcode = result.extras?.["com.symbol.datawedge.data_string"];
|
|
174
|
+
// handle barcode
|
|
102
175
|
},
|
|
103
176
|
);
|
|
104
177
|
|
|
@@ -106,28 +179,25 @@ const unsubscribe = await Intent.subscribe(
|
|
|
106
179
|
await unsubscribe();
|
|
107
180
|
```
|
|
108
181
|
|
|
109
|
-
### Send a broadcast
|
|
182
|
+
### Send a broadcast and start an activity for result
|
|
110
183
|
|
|
111
|
-
```
|
|
184
|
+
```typescript
|
|
112
185
|
import { Intent } from "@simplysm/capacitor-plugin-intent";
|
|
113
186
|
|
|
187
|
+
// Send a broadcast
|
|
114
188
|
await Intent.send({
|
|
115
|
-
action: "com.
|
|
116
|
-
extras: {
|
|
189
|
+
action: "com.symbol.datawedge.api.ACTION",
|
|
190
|
+
extras: {
|
|
191
|
+
"com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING",
|
|
192
|
+
},
|
|
117
193
|
});
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### Start an activity for result
|
|
121
|
-
|
|
122
|
-
```ts
|
|
123
|
-
import { Intent } from "@simplysm/capacitor-plugin-intent";
|
|
124
194
|
|
|
195
|
+
// Start an activity for result
|
|
125
196
|
const result = await Intent.startActivityForResult({
|
|
126
|
-
action: "
|
|
127
|
-
|
|
197
|
+
action: "com.example.PAY",
|
|
198
|
+
extras: { amount: 1000 },
|
|
128
199
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
loadImage(result.data.uri);
|
|
200
|
+
if (result.resultCode === -1) {
|
|
201
|
+
// RESULT_OK - payment succeeded
|
|
132
202
|
}
|
|
133
203
|
```
|