@simplysm/capacitor-plugin-intent 12.16.41 → 14.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/android/build.gradle +1 -0
- package/android/src/main/kotlin/kr/co/simplysm/capacitor/intent/IntentPlugin.kt +365 -0
- package/dist/Intent.d.ts +75 -0
- package/dist/Intent.d.ts.map +1 -0
- package/dist/Intent.js +99 -0
- package/dist/Intent.js.map +1 -0
- package/dist/IntentPlugin.d.ts +72 -0
- package/dist/IntentPlugin.d.ts.map +1 -0
- package/dist/IntentPlugin.js +2 -0
- package/dist/IntentPlugin.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/web/IntentWeb.d.ts +21 -0
- package/dist/web/IntentWeb.d.ts.map +1 -0
- package/dist/web/IntentWeb.js +28 -0
- package/dist/web/IntentWeb.js.map +1 -0
- package/package.json +15 -10
- package/src/Intent.ts +56 -25
- package/src/IntentPlugin.ts +81 -0
- package/src/index.ts +2 -1
- package/src/web/IntentWeb.ts +27 -16
- package/README.md +0 -188
- package/android/src/main/java/kr/co/simplysm/capacitor/intent/IntentPlugin.java +0 -376
- package/dist/src/IIntentPlugin.d.ts +0 -63
- package/dist/src/IIntentPlugin.js +0 -1
- package/dist/src/Intent.d.ts +0 -64
- package/dist/src/Intent.js +0 -80
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -2
- package/dist/src/web/IntentWeb.d.ts +0 -19
- package/dist/src/web/IntentWeb.js +0 -24
- package/src/IIntentPlugin.ts +0 -65
- package/tests/slice1-directory-and-config.spec.ts +0 -50
- package/tests/slice2-java-renaming.spec.ts +0 -34
- package/tests/slice3-typescript-renaming.spec.ts +0 -76
- package/tests/slice4-docs-and-deprecation.spec.ts +0 -31
- package/tests/slice5-start-activity-for-result-android.spec.md +0 -98
- package/tests/slice5-start-activity-for-result-types.spec.ts +0 -40
- package/tests/slice6-start-activity-for-result-web.spec.ts +0 -34
- package/tsconfig.json +0 -8
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
package kr.co.simplysm.capacitor.intent;
|
|
2
|
-
|
|
3
|
-
import android.content.BroadcastReceiver;
|
|
4
|
-
import android.content.ComponentName;
|
|
5
|
-
import android.content.Context;
|
|
6
|
-
import android.content.Intent;
|
|
7
|
-
import android.content.IntentFilter;
|
|
8
|
-
import android.net.Uri;
|
|
9
|
-
import android.os.Build;
|
|
10
|
-
import android.os.Bundle;
|
|
11
|
-
import android.os.Parcelable;
|
|
12
|
-
import android.util.Log;
|
|
13
|
-
|
|
14
|
-
import androidx.activity.result.ActivityResult;
|
|
15
|
-
|
|
16
|
-
import com.getcapacitor.JSArray;
|
|
17
|
-
import com.getcapacitor.JSObject;
|
|
18
|
-
import com.getcapacitor.Plugin;
|
|
19
|
-
import com.getcapacitor.PluginCall;
|
|
20
|
-
import com.getcapacitor.PluginMethod;
|
|
21
|
-
import com.getcapacitor.annotation.ActivityCallback;
|
|
22
|
-
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
23
|
-
|
|
24
|
-
import org.json.JSONArray;
|
|
25
|
-
import org.json.JSONException;
|
|
26
|
-
import org.json.JSONObject;
|
|
27
|
-
|
|
28
|
-
import java.util.HashMap;
|
|
29
|
-
import java.util.Iterator;
|
|
30
|
-
import java.util.Map;
|
|
31
|
-
import java.util.Set;
|
|
32
|
-
import java.util.UUID;
|
|
33
|
-
|
|
34
|
-
@CapacitorPlugin(name = "Intent")
|
|
35
|
-
public class IntentPlugin extends Plugin {
|
|
36
|
-
|
|
37
|
-
private static final String TAG = "IntentPlugin";
|
|
38
|
-
private final Map<String, BroadcastReceiver> receivers = new HashMap<>();
|
|
39
|
-
|
|
40
|
-
@Override
|
|
41
|
-
protected void handleOnNewIntent(Intent intent) {
|
|
42
|
-
super.handleOnNewIntent(intent);
|
|
43
|
-
notifyListeners("onNewIntent", intentToJson(intent));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@PluginMethod(returnType = PluginMethod.RETURN_CALLBACK)
|
|
47
|
-
public void subscribe(PluginCall call) {
|
|
48
|
-
try {
|
|
49
|
-
JSArray filters = call.getArray("filters");
|
|
50
|
-
|
|
51
|
-
if (filters == null || filters.length() == 0) {
|
|
52
|
-
call.reject("filters is required");
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
call.setKeepAlive(true);
|
|
57
|
-
|
|
58
|
-
String receiverId = UUID.randomUUID().toString();
|
|
59
|
-
|
|
60
|
-
IntentFilter intentFilter = new IntentFilter();
|
|
61
|
-
for (int i = 0; i < filters.length(); i++) {
|
|
62
|
-
intentFilter.addAction(filters.getString(i));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
BroadcastReceiver receiver = new BroadcastReceiver() {
|
|
66
|
-
@Override
|
|
67
|
-
public void onReceive(Context context, Intent intent) {
|
|
68
|
-
JSObject result = intentToJson(intent);
|
|
69
|
-
result.put("id", receiverId);
|
|
70
|
-
call.resolve(result);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
75
|
-
getContext().registerReceiver(receiver, intentFilter, Context.RECEIVER_EXPORTED);
|
|
76
|
-
} else {
|
|
77
|
-
getContext().registerReceiver(receiver, intentFilter);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
receivers.put(receiverId, receiver);
|
|
81
|
-
|
|
82
|
-
JSObject ret = new JSObject();
|
|
83
|
-
ret.put("id", receiverId);
|
|
84
|
-
call.resolve(ret);
|
|
85
|
-
} catch (Exception e) {
|
|
86
|
-
Log.e(TAG, "subscribe failed", e);
|
|
87
|
-
call.reject("subscribe failed: " + e.getMessage());
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@PluginMethod
|
|
92
|
-
public void unsubscribe(PluginCall call) {
|
|
93
|
-
try {
|
|
94
|
-
String id = call.getString("id");
|
|
95
|
-
if (id == null) {
|
|
96
|
-
call.reject("id is required");
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
BroadcastReceiver receiver = receivers.remove(id);
|
|
101
|
-
if (receiver != null) {
|
|
102
|
-
getContext().unregisterReceiver(receiver);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
call.resolve();
|
|
106
|
-
} catch (Exception e) {
|
|
107
|
-
Log.e(TAG, "unsubscribe failed", e);
|
|
108
|
-
call.reject("unsubscribe failed: " + e.getMessage());
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
@PluginMethod
|
|
113
|
-
public void unsubscribeAll(PluginCall call) {
|
|
114
|
-
try {
|
|
115
|
-
for (BroadcastReceiver receiver : receivers.values()) {
|
|
116
|
-
try {
|
|
117
|
-
getContext().unregisterReceiver(receiver);
|
|
118
|
-
} catch (Exception ignored) {
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
receivers.clear();
|
|
122
|
-
call.resolve();
|
|
123
|
-
} catch (Exception e) {
|
|
124
|
-
Log.e(TAG, "unsubscribeAll failed", e);
|
|
125
|
-
call.reject("unsubscribeAll failed: " + e.getMessage());
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
@PluginMethod
|
|
130
|
-
public void send(PluginCall call) {
|
|
131
|
-
try {
|
|
132
|
-
String action = call.getString("action");
|
|
133
|
-
if (action == null) {
|
|
134
|
-
call.reject("action is required");
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
Intent intent = new Intent(action);
|
|
139
|
-
|
|
140
|
-
JSObject extras = call.getObject("extras");
|
|
141
|
-
if (extras != null) {
|
|
142
|
-
populateExtras(intent, extras);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
getContext().sendBroadcast(intent);
|
|
146
|
-
call.resolve();
|
|
147
|
-
} catch (Exception e) {
|
|
148
|
-
Log.e(TAG, "send failed", e);
|
|
149
|
-
call.reject("send failed: " + e.getMessage());
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
@PluginMethod
|
|
154
|
-
public void getLaunchIntent(PluginCall call) {
|
|
155
|
-
try {
|
|
156
|
-
Intent intent = getActivity().getIntent();
|
|
157
|
-
call.resolve(intentToJson(intent));
|
|
158
|
-
} catch (Exception e) {
|
|
159
|
-
Log.e(TAG, "getLaunchIntent failed", e);
|
|
160
|
-
call.reject("getLaunchIntent failed: " + e.getMessage());
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
@PluginMethod
|
|
165
|
-
public void startActivityForResult(PluginCall call) {
|
|
166
|
-
try {
|
|
167
|
-
String action = call.getString("action");
|
|
168
|
-
if (action == null) {
|
|
169
|
-
call.reject("action is required");
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
Intent intent = new Intent(action);
|
|
174
|
-
|
|
175
|
-
String uri = call.getString("uri");
|
|
176
|
-
String type = call.getString("type");
|
|
177
|
-
if (uri != null && type != null) {
|
|
178
|
-
intent.setDataAndType(Uri.parse(uri), type);
|
|
179
|
-
} else if (uri != null) {
|
|
180
|
-
intent.setData(Uri.parse(uri));
|
|
181
|
-
} else if (type != null) {
|
|
182
|
-
intent.setType(type);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
String pkg = call.getString("package");
|
|
186
|
-
String component = call.getString("component");
|
|
187
|
-
if (component != null && pkg == null) {
|
|
188
|
-
call.reject("component requires package");
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
if (pkg != null && component != null) {
|
|
192
|
-
intent.setComponent(new ComponentName(pkg, component));
|
|
193
|
-
} else if (pkg != null) {
|
|
194
|
-
intent.setPackage(pkg);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
JSObject extras = call.getObject("extras");
|
|
198
|
-
if (extras != null) {
|
|
199
|
-
populateExtras(intent, extras);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
startActivityForResult(call, intent, "onActivityResult");
|
|
203
|
-
} catch (Exception e) {
|
|
204
|
-
Log.e(TAG, "startActivityForResult failed", e);
|
|
205
|
-
call.reject("startActivityForResult failed: " + e.getMessage());
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
@ActivityCallback
|
|
210
|
-
private void onActivityResult(PluginCall call, ActivityResult result) {
|
|
211
|
-
if (call == null) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
JSObject ret = new JSObject();
|
|
216
|
-
ret.put("resultCode", result.getResultCode());
|
|
217
|
-
|
|
218
|
-
Intent data = result.getData();
|
|
219
|
-
if (data != null) {
|
|
220
|
-
String dataString = data.getDataString();
|
|
221
|
-
if (dataString != null) {
|
|
222
|
-
ret.put("data", dataString);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
Bundle extras = data.getExtras();
|
|
226
|
-
if (extras != null && !extras.isEmpty()) {
|
|
227
|
-
ret.put("extras", bundleToJson(extras));
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
call.resolve(ret);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
private void populateExtras(Intent intent, JSObject extras) throws JSONException {
|
|
235
|
-
Iterator<String> keys = extras.keys();
|
|
236
|
-
while (keys.hasNext()) {
|
|
237
|
-
String key = keys.next();
|
|
238
|
-
Object value = extras.get(key);
|
|
239
|
-
|
|
240
|
-
if (value instanceof String) {
|
|
241
|
-
intent.putExtra(key, (String) value);
|
|
242
|
-
} else if (value instanceof Integer) {
|
|
243
|
-
intent.putExtra(key, (Integer) value);
|
|
244
|
-
} else if (value instanceof Long) {
|
|
245
|
-
intent.putExtra(key, (Long) value);
|
|
246
|
-
} else if (value instanceof Double) {
|
|
247
|
-
intent.putExtra(key, (Double) value);
|
|
248
|
-
} else if (value instanceof Boolean) {
|
|
249
|
-
intent.putExtra(key, (Boolean) value);
|
|
250
|
-
} else if (value instanceof JSONArray) {
|
|
251
|
-
JSONArray arr = (JSONArray) value;
|
|
252
|
-
String[] strArr = new String[arr.length()];
|
|
253
|
-
for (int i = 0; i < arr.length(); i++) {
|
|
254
|
-
strArr[i] = arr.getString(i);
|
|
255
|
-
}
|
|
256
|
-
intent.putExtra(key, strArr);
|
|
257
|
-
} else if (value instanceof JSONObject) {
|
|
258
|
-
Bundle bundle = jsonToBundle((JSONObject) value);
|
|
259
|
-
intent.putExtra(key, bundle);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
private Bundle jsonToBundle(JSONObject json) throws JSONException {
|
|
265
|
-
Bundle bundle = new Bundle();
|
|
266
|
-
Iterator<String> keys = json.keys();
|
|
267
|
-
while (keys.hasNext()) {
|
|
268
|
-
String key = keys.next();
|
|
269
|
-
Object value = json.get(key);
|
|
270
|
-
|
|
271
|
-
if (value instanceof String) {
|
|
272
|
-
bundle.putString(key, (String) value);
|
|
273
|
-
} else if (value instanceof Integer) {
|
|
274
|
-
bundle.putInt(key, (Integer) value);
|
|
275
|
-
} else if (value instanceof Long) {
|
|
276
|
-
bundle.putLong(key, (Long) value);
|
|
277
|
-
} else if (value instanceof Double) {
|
|
278
|
-
bundle.putDouble(key, (Double) value);
|
|
279
|
-
} else if (value instanceof Boolean) {
|
|
280
|
-
bundle.putBoolean(key, (Boolean) value);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return bundle;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
private JSObject intentToJson(Intent intent) {
|
|
287
|
-
JSObject json = new JSObject();
|
|
288
|
-
|
|
289
|
-
if (intent == null) {
|
|
290
|
-
return json;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
try {
|
|
294
|
-
json.put("action", intent.getAction());
|
|
295
|
-
|
|
296
|
-
Bundle extras = intent.getExtras();
|
|
297
|
-
if (extras != null) {
|
|
298
|
-
json.put("extras", bundleToJson(extras));
|
|
299
|
-
}
|
|
300
|
-
} catch (Exception e) {
|
|
301
|
-
Log.e(TAG, "intentToJson failed", e);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
return json;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
private JSObject bundleToJson(Bundle bundle) {
|
|
308
|
-
JSObject json = new JSObject();
|
|
309
|
-
|
|
310
|
-
if (bundle == null) {
|
|
311
|
-
return json;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
for (String key : bundle.keySet()) {
|
|
315
|
-
try {
|
|
316
|
-
Object value = bundle.get(key);
|
|
317
|
-
|
|
318
|
-
if (value == null) {
|
|
319
|
-
json.put(key, JSONObject.NULL);
|
|
320
|
-
} else if (value instanceof String) {
|
|
321
|
-
json.put(key, value);
|
|
322
|
-
} else if (value instanceof Integer) {
|
|
323
|
-
json.put(key, value);
|
|
324
|
-
} else if (value instanceof Long) {
|
|
325
|
-
json.put(key, value);
|
|
326
|
-
} else if (value instanceof Double) {
|
|
327
|
-
json.put(key, value);
|
|
328
|
-
} else if (value instanceof Float) {
|
|
329
|
-
json.put(key, ((Float) value).doubleValue());
|
|
330
|
-
} else if (value instanceof Boolean) {
|
|
331
|
-
json.put(key, value);
|
|
332
|
-
} else if (value instanceof Bundle) {
|
|
333
|
-
json.put(key, bundleToJson((Bundle) value));
|
|
334
|
-
} else if (value instanceof String[]) {
|
|
335
|
-
JSArray arr = new JSArray();
|
|
336
|
-
for (String s : (String[]) value) {
|
|
337
|
-
arr.put(s);
|
|
338
|
-
}
|
|
339
|
-
json.put(key, arr);
|
|
340
|
-
} else if (value instanceof int[]) {
|
|
341
|
-
JSArray arr = new JSArray();
|
|
342
|
-
for (int i : (int[]) value) {
|
|
343
|
-
arr.put(i);
|
|
344
|
-
}
|
|
345
|
-
json.put(key, arr);
|
|
346
|
-
} else if (value instanceof Parcelable) {
|
|
347
|
-
json.put(key, value.toString());
|
|
348
|
-
} else if (value instanceof Parcelable[]) {
|
|
349
|
-
JSArray arr = new JSArray();
|
|
350
|
-
for (Parcelable p : (Parcelable[]) value) {
|
|
351
|
-
arr.put(p.toString());
|
|
352
|
-
}
|
|
353
|
-
json.put(key, arr);
|
|
354
|
-
} else {
|
|
355
|
-
json.put(key, value.toString());
|
|
356
|
-
}
|
|
357
|
-
} catch (Exception e) {
|
|
358
|
-
Log.w(TAG, "bundleToJson key failed: " + key, e);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
return json;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
@Override
|
|
366
|
-
protected void handleOnDestroy() {
|
|
367
|
-
for (BroadcastReceiver receiver : receivers.values()) {
|
|
368
|
-
try {
|
|
369
|
-
getContext().unregisterReceiver(receiver);
|
|
370
|
-
} catch (Exception ignored) {
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
receivers.clear();
|
|
374
|
-
super.handleOnDestroy();
|
|
375
|
-
}
|
|
376
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
export interface IIntentResult {
|
|
2
|
-
/** Intent action */
|
|
3
|
-
action?: string;
|
|
4
|
-
/** Extra data */
|
|
5
|
-
extras?: Record<string, unknown>;
|
|
6
|
-
}
|
|
7
|
-
export interface IStartActivityForResultOptions {
|
|
8
|
-
/** Intent action */
|
|
9
|
-
action: string;
|
|
10
|
-
/** Data URI */
|
|
11
|
-
uri?: string;
|
|
12
|
-
/** Extra data */
|
|
13
|
-
extras?: Record<string, unknown>;
|
|
14
|
-
/** Target package name */
|
|
15
|
-
package?: string;
|
|
16
|
-
/** Target component class name */
|
|
17
|
-
component?: string;
|
|
18
|
-
/** MIME type */
|
|
19
|
-
type?: string;
|
|
20
|
-
}
|
|
21
|
-
export interface IActivityResult {
|
|
22
|
-
/** Activity result code (RESULT_OK = -1, RESULT_CANCELED = 0) */
|
|
23
|
-
resultCode: number;
|
|
24
|
-
/** Result data URI */
|
|
25
|
-
data?: string;
|
|
26
|
-
/** Result extras */
|
|
27
|
-
extras?: Record<string, unknown>;
|
|
28
|
-
}
|
|
29
|
-
export interface IIntentPlugin {
|
|
30
|
-
/**
|
|
31
|
-
* Intent 수신기 등록
|
|
32
|
-
*/
|
|
33
|
-
subscribe(options: {
|
|
34
|
-
filters: string[];
|
|
35
|
-
}, callback: (result: IIntentResult) => void): Promise<{
|
|
36
|
-
id: string;
|
|
37
|
-
}>;
|
|
38
|
-
/**
|
|
39
|
-
* 특정 Intent 수신기 해제
|
|
40
|
-
*/
|
|
41
|
-
unsubscribe(options: {
|
|
42
|
-
id: string;
|
|
43
|
-
}): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* 모든 Intent 수신기 해제
|
|
46
|
-
*/
|
|
47
|
-
unsubscribeAll(): Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
* Intent 전송
|
|
50
|
-
*/
|
|
51
|
-
send(options: {
|
|
52
|
-
action: string;
|
|
53
|
-
extras?: Record<string, unknown>;
|
|
54
|
-
}): Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
* 앱 시작 Intent 가져오기
|
|
57
|
-
*/
|
|
58
|
-
getLaunchIntent(): Promise<IIntentResult>;
|
|
59
|
-
/**
|
|
60
|
-
* Activity 시작 후 결과 수신
|
|
61
|
-
*/
|
|
62
|
-
startActivityForResult(options: IStartActivityForResultOptions): Promise<IActivityResult>;
|
|
63
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/src/Intent.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { IActivityResult, IIntentResult, IStartActivityForResultOptions } from "./IIntentPlugin";
|
|
2
|
-
/**
|
|
3
|
-
* Android Intent 송수신 플러그인
|
|
4
|
-
* - 산업용 장치(바코드 스캐너, PDA 등) 연동용
|
|
5
|
-
*/
|
|
6
|
-
export declare abstract class Intent {
|
|
7
|
-
/**
|
|
8
|
-
* Intent 수신 등록
|
|
9
|
-
* @returns 해제 함수
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const unsub = await Intent.subscribe(
|
|
14
|
-
* ["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
15
|
-
* (result) => console.log(result.extras)
|
|
16
|
-
* );
|
|
17
|
-
*
|
|
18
|
-
* // 해제
|
|
19
|
-
* unsub();
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
static subscribe(filters: string[], callback: (result: IIntentResult) => void): Promise<() => Promise<void>>;
|
|
23
|
-
/**
|
|
24
|
-
* 모든 Intent 수신기 해제
|
|
25
|
-
*/
|
|
26
|
-
static unsubscribeAll(): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* Intent 전송
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* await Intent.send({
|
|
33
|
-
* action: "com.symbol.datawedge.api.ACTION",
|
|
34
|
-
* extras: {
|
|
35
|
-
* "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING"
|
|
36
|
-
* }
|
|
37
|
-
* });
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
static send(options: {
|
|
41
|
-
action: string;
|
|
42
|
-
extras?: Record<string, unknown>;
|
|
43
|
-
}): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* 앱 시작 Intent 가져오기
|
|
46
|
-
*/
|
|
47
|
-
static getLaunchIntent(): Promise<IIntentResult>;
|
|
48
|
-
/**
|
|
49
|
-
* Activity 시작 후 결과 수신
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* const result = await Intent.startActivityForResult({
|
|
54
|
-
* action: "android.intent.action.GET_CONTENT",
|
|
55
|
-
* type: "image/*",
|
|
56
|
-
* });
|
|
57
|
-
*
|
|
58
|
-
* if (result.resultCode === -1) { // RESULT_OK
|
|
59
|
-
* console.log("Selected:", result.data);
|
|
60
|
-
* }
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
static startActivityForResult(options: IStartActivityForResultOptions): Promise<IActivityResult>;
|
|
64
|
-
}
|
package/dist/src/Intent.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { registerPlugin } from "@capacitor/core";
|
|
2
|
-
const IntentPlugin = registerPlugin("Intent", {
|
|
3
|
-
web: async () => {
|
|
4
|
-
const { IntentWeb } = await import("./web/IntentWeb");
|
|
5
|
-
return new IntentWeb();
|
|
6
|
-
},
|
|
7
|
-
});
|
|
8
|
-
/**
|
|
9
|
-
* Android Intent 송수신 플러그인
|
|
10
|
-
* - 산업용 장치(바코드 스캐너, PDA 등) 연동용
|
|
11
|
-
*/
|
|
12
|
-
export class Intent {
|
|
13
|
-
/**
|
|
14
|
-
* Intent 수신 등록
|
|
15
|
-
* @returns 해제 함수
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const unsub = await Intent.subscribe(
|
|
20
|
-
* ["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
21
|
-
* (result) => console.log(result.extras)
|
|
22
|
-
* );
|
|
23
|
-
*
|
|
24
|
-
* // 해제
|
|
25
|
-
* unsub();
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
static async subscribe(filters, callback) {
|
|
29
|
-
const { id } = await IntentPlugin.subscribe({ filters }, callback);
|
|
30
|
-
return async () => {
|
|
31
|
-
await IntentPlugin.unsubscribe({ id });
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* 모든 Intent 수신기 해제
|
|
36
|
-
*/
|
|
37
|
-
static async unsubscribeAll() {
|
|
38
|
-
await IntentPlugin.unsubscribeAll();
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Intent 전송
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* await Intent.send({
|
|
46
|
-
* action: "com.symbol.datawedge.api.ACTION",
|
|
47
|
-
* extras: {
|
|
48
|
-
* "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING"
|
|
49
|
-
* }
|
|
50
|
-
* });
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
static async send(options) {
|
|
54
|
-
await IntentPlugin.send(options);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 앱 시작 Intent 가져오기
|
|
58
|
-
*/
|
|
59
|
-
static async getLaunchIntent() {
|
|
60
|
-
return await IntentPlugin.getLaunchIntent();
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Activity 시작 후 결과 수신
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* const result = await Intent.startActivityForResult({
|
|
68
|
-
* action: "android.intent.action.GET_CONTENT",
|
|
69
|
-
* type: "image/*",
|
|
70
|
-
* });
|
|
71
|
-
*
|
|
72
|
-
* if (result.resultCode === -1) { // RESULT_OK
|
|
73
|
-
* console.log("Selected:", result.data);
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
static async startActivityForResult(options) {
|
|
78
|
-
return await IntentPlugin.startActivityForResult(options);
|
|
79
|
-
}
|
|
80
|
-
}
|
package/dist/src/index.d.ts
DELETED
package/dist/src/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { WebPlugin } from "@capacitor/core";
|
|
2
|
-
import { IActivityResult, IIntentPlugin, IIntentResult, IStartActivityForResultOptions } from "../IIntentPlugin";
|
|
3
|
-
export declare class IntentWeb extends WebPlugin implements IIntentPlugin {
|
|
4
|
-
subscribe(_options: {
|
|
5
|
-
filters: string[];
|
|
6
|
-
}, _callback: (result: IIntentResult) => void): Promise<{
|
|
7
|
-
id: string;
|
|
8
|
-
}>;
|
|
9
|
-
unsubscribe(_options: {
|
|
10
|
-
id: string;
|
|
11
|
-
}): Promise<void>;
|
|
12
|
-
unsubscribeAll(): Promise<void>;
|
|
13
|
-
send(_options: {
|
|
14
|
-
action: string;
|
|
15
|
-
extras?: Record<string, unknown>;
|
|
16
|
-
}): Promise<void>;
|
|
17
|
-
getLaunchIntent(): Promise<IIntentResult>;
|
|
18
|
-
startActivityForResult(_options: IStartActivityForResultOptions): Promise<IActivityResult>;
|
|
19
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { WebPlugin } from "@capacitor/core";
|
|
2
|
-
export class IntentWeb extends WebPlugin {
|
|
3
|
-
async subscribe(_options, _callback) {
|
|
4
|
-
alert("[Intent] 웹 환경에서는 Intent를 지원하지 않습니다.");
|
|
5
|
-
return await Promise.resolve({ id: "web-stub" });
|
|
6
|
-
}
|
|
7
|
-
async unsubscribe(_options) {
|
|
8
|
-
await Promise.resolve();
|
|
9
|
-
}
|
|
10
|
-
async unsubscribeAll() {
|
|
11
|
-
await Promise.resolve();
|
|
12
|
-
}
|
|
13
|
-
async send(_options) {
|
|
14
|
-
alert("[Intent] 웹 환경에서는 Intent를 지원하지 않습니다.");
|
|
15
|
-
await Promise.resolve();
|
|
16
|
-
}
|
|
17
|
-
async getLaunchIntent() {
|
|
18
|
-
return await Promise.resolve({});
|
|
19
|
-
}
|
|
20
|
-
async startActivityForResult(_options) {
|
|
21
|
-
alert("[Intent] 웹 환경에서는 startActivityForResult를 지원하지 않습니다.");
|
|
22
|
-
return await Promise.resolve({ resultCode: 0 });
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/IIntentPlugin.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export interface IIntentResult {
|
|
2
|
-
/** Intent action */
|
|
3
|
-
action?: string;
|
|
4
|
-
/** Extra data */
|
|
5
|
-
extras?: Record<string, unknown>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface IStartActivityForResultOptions {
|
|
9
|
-
/** Intent action */
|
|
10
|
-
action: string;
|
|
11
|
-
/** Data URI */
|
|
12
|
-
uri?: string;
|
|
13
|
-
/** Extra data */
|
|
14
|
-
extras?: Record<string, unknown>;
|
|
15
|
-
/** Target package name */
|
|
16
|
-
package?: string;
|
|
17
|
-
/** Target component class name */
|
|
18
|
-
component?: string;
|
|
19
|
-
/** MIME type */
|
|
20
|
-
type?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface IActivityResult {
|
|
24
|
-
/** Activity result code (RESULT_OK = -1, RESULT_CANCELED = 0) */
|
|
25
|
-
resultCode: number;
|
|
26
|
-
/** Result data URI */
|
|
27
|
-
data?: string;
|
|
28
|
-
/** Result extras */
|
|
29
|
-
extras?: Record<string, unknown>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface IIntentPlugin {
|
|
33
|
-
/**
|
|
34
|
-
* Intent 수신기 등록
|
|
35
|
-
*/
|
|
36
|
-
subscribe(
|
|
37
|
-
options: { filters: string[] },
|
|
38
|
-
callback: (result: IIntentResult) => void,
|
|
39
|
-
): Promise<{ id: string }>;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 특정 Intent 수신기 해제
|
|
43
|
-
*/
|
|
44
|
-
unsubscribe(options: { id: string }): Promise<void>;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 모든 Intent 수신기 해제
|
|
48
|
-
*/
|
|
49
|
-
unsubscribeAll(): Promise<void>;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Intent 전송
|
|
53
|
-
*/
|
|
54
|
-
send(options: { action: string; extras?: Record<string, unknown> }): Promise<void>;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 앱 시작 Intent 가져오기
|
|
58
|
-
*/
|
|
59
|
-
getLaunchIntent(): Promise<IIntentResult>;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Activity 시작 후 결과 수신
|
|
63
|
-
*/
|
|
64
|
-
startActivityForResult(options: IStartActivityForResultOptions): Promise<IActivityResult>;
|
|
65
|
-
}
|