@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
package/android/build.gradle
CHANGED
|
@@ -0,0 +1,365 @@
|
|
|
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
|
+
import androidx.activity.result.ActivityResult
|
|
14
|
+
import com.getcapacitor.JSArray
|
|
15
|
+
import com.getcapacitor.JSObject
|
|
16
|
+
import com.getcapacitor.Plugin
|
|
17
|
+
import com.getcapacitor.PluginCall
|
|
18
|
+
import com.getcapacitor.PluginMethod
|
|
19
|
+
import com.getcapacitor.annotation.ActivityCallback
|
|
20
|
+
import com.getcapacitor.annotation.CapacitorPlugin
|
|
21
|
+
import org.json.JSONArray
|
|
22
|
+
import org.json.JSONException
|
|
23
|
+
import org.json.JSONObject
|
|
24
|
+
import java.util.UUID
|
|
25
|
+
|
|
26
|
+
@CapacitorPlugin(name = "Intent")
|
|
27
|
+
class IntentPlugin : Plugin() {
|
|
28
|
+
|
|
29
|
+
companion object {
|
|
30
|
+
private const val TAG = "IntentPlugin"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private val receivers = mutableMapOf<String, BroadcastReceiver>()
|
|
34
|
+
|
|
35
|
+
override fun handleOnNewIntent(intent: Intent) {
|
|
36
|
+
super.handleOnNewIntent(intent)
|
|
37
|
+
notifyListeners("newIntent", intentToJson(intent))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@PluginMethod(returnType = PluginMethod.RETURN_CALLBACK)
|
|
41
|
+
fun subscribe(call: PluginCall) {
|
|
42
|
+
try {
|
|
43
|
+
val filters = call.getArray("filters")
|
|
44
|
+
|
|
45
|
+
if (filters == null || filters.length() == 0) {
|
|
46
|
+
call.reject("filters is required")
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
call.setKeepAlive(true)
|
|
51
|
+
|
|
52
|
+
val receiverId = UUID.randomUUID().toString()
|
|
53
|
+
|
|
54
|
+
val intentFilter = IntentFilter()
|
|
55
|
+
for (i in 0 until filters.length()) {
|
|
56
|
+
intentFilter.addAction(filters.getString(i))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
val receiver = object : BroadcastReceiver() {
|
|
60
|
+
override fun onReceive(context: Context, intent: Intent) {
|
|
61
|
+
val result = intentToJson(intent)
|
|
62
|
+
result.put("id", receiverId)
|
|
63
|
+
call.resolve(result)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
68
|
+
context.registerReceiver(receiver, intentFilter, Context.RECEIVER_EXPORTED)
|
|
69
|
+
} else {
|
|
70
|
+
context.registerReceiver(receiver, intentFilter)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
receivers[receiverId] = receiver
|
|
74
|
+
|
|
75
|
+
val ret = JSObject()
|
|
76
|
+
ret.put("id", receiverId)
|
|
77
|
+
call.resolve(ret)
|
|
78
|
+
} catch (e: Exception) {
|
|
79
|
+
Log.e(TAG, "subscribe failed", e)
|
|
80
|
+
call.reject("subscribe failed: " + e.message)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@PluginMethod
|
|
85
|
+
fun unsubscribe(call: PluginCall) {
|
|
86
|
+
try {
|
|
87
|
+
val id = call.getString("id")
|
|
88
|
+
if (id == null) {
|
|
89
|
+
call.reject("id is required")
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
val receiver = receivers.remove(id)
|
|
94
|
+
if (receiver != null) {
|
|
95
|
+
context.unregisterReceiver(receiver)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
call.resolve()
|
|
99
|
+
} catch (e: Exception) {
|
|
100
|
+
Log.e(TAG, "unsubscribe failed", e)
|
|
101
|
+
call.reject("unsubscribe failed: " + e.message)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@PluginMethod
|
|
106
|
+
fun unsubscribeAll(call: PluginCall) {
|
|
107
|
+
try {
|
|
108
|
+
for (receiver in receivers.values) {
|
|
109
|
+
try {
|
|
110
|
+
context.unregisterReceiver(receiver)
|
|
111
|
+
} catch (ignored: Exception) {
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
receivers.clear()
|
|
115
|
+
call.resolve()
|
|
116
|
+
} catch (e: Exception) {
|
|
117
|
+
Log.e(TAG, "unsubscribeAll failed", e)
|
|
118
|
+
call.reject("unsubscribeAll failed: " + e.message)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@PluginMethod
|
|
123
|
+
fun send(call: PluginCall) {
|
|
124
|
+
try {
|
|
125
|
+
val action = call.getString("action")
|
|
126
|
+
if (action == null) {
|
|
127
|
+
call.reject("action is required")
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
val intent = Intent(action)
|
|
132
|
+
|
|
133
|
+
val extras = call.getObject("extras")
|
|
134
|
+
if (extras != null) {
|
|
135
|
+
populateExtras(intent, extras)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
context.sendBroadcast(intent)
|
|
139
|
+
call.resolve()
|
|
140
|
+
} catch (e: Exception) {
|
|
141
|
+
Log.e(TAG, "send failed", e)
|
|
142
|
+
call.reject("send failed: " + e.message)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@PluginMethod
|
|
147
|
+
fun getLaunchIntent(call: PluginCall) {
|
|
148
|
+
try {
|
|
149
|
+
val intent = activity.intent
|
|
150
|
+
call.resolve(intentToJson(intent))
|
|
151
|
+
} catch (e: Exception) {
|
|
152
|
+
Log.e(TAG, "getLaunchIntent failed", e)
|
|
153
|
+
call.reject("getLaunchIntent failed: " + e.message)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@PluginMethod
|
|
158
|
+
fun startActivityForResult(call: PluginCall) {
|
|
159
|
+
try {
|
|
160
|
+
val intent = buildIntent(call)
|
|
161
|
+
startActivityForResult(call, intent, "handleActivityResult")
|
|
162
|
+
} catch (e: Exception) {
|
|
163
|
+
Log.e(TAG, "startActivityForResult failed", e)
|
|
164
|
+
call.reject("startActivityForResult failed: " + e.message)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@ActivityCallback
|
|
169
|
+
private fun handleActivityResult(call: PluginCall?, result: ActivityResult) {
|
|
170
|
+
if (call == null) {
|
|
171
|
+
return
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
val json = JSObject()
|
|
175
|
+
json.put("resultCode", result.resultCode)
|
|
176
|
+
|
|
177
|
+
val data = result.data
|
|
178
|
+
if (data != null) {
|
|
179
|
+
val dataJson = JSObject()
|
|
180
|
+
if (data.action != null) {
|
|
181
|
+
dataJson.put("action", data.action)
|
|
182
|
+
}
|
|
183
|
+
if (data.data != null) {
|
|
184
|
+
dataJson.put("uri", data.data.toString())
|
|
185
|
+
}
|
|
186
|
+
val extras = data.extras
|
|
187
|
+
if (extras != null) {
|
|
188
|
+
dataJson.put("extras", bundleToJson(extras))
|
|
189
|
+
}
|
|
190
|
+
json.put("data", dataJson)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
call.resolve(json)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private fun buildIntent(call: PluginCall): Intent {
|
|
197
|
+
val intent = Intent()
|
|
198
|
+
|
|
199
|
+
val action = call.getString("action")
|
|
200
|
+
if (action != null) {
|
|
201
|
+
intent.action = action
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
val uri = call.getString("uri")
|
|
205
|
+
val type = call.getString("type")
|
|
206
|
+
when {
|
|
207
|
+
uri != null && type != null -> intent.setDataAndType(Uri.parse(uri), type)
|
|
208
|
+
uri != null -> intent.data = Uri.parse(uri)
|
|
209
|
+
type != null -> intent.type = type
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
val extras = call.getObject("extras")
|
|
213
|
+
if (extras != null) {
|
|
214
|
+
populateExtras(intent, extras)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
val packageName = call.getString("packageName")
|
|
218
|
+
val className = call.getString("className")
|
|
219
|
+
when {
|
|
220
|
+
packageName != null && className != null ->
|
|
221
|
+
intent.component = ComponentName(packageName, className)
|
|
222
|
+
packageName != null -> intent.setPackage(packageName)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
val flags = call.getInt("flags")
|
|
226
|
+
if (flags != null) {
|
|
227
|
+
intent.addFlags(flags)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return intent
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@Throws(JSONException::class)
|
|
234
|
+
private fun populateExtras(intent: Intent, extras: JSObject) {
|
|
235
|
+
val keys = extras.keys()
|
|
236
|
+
while (keys.hasNext()) {
|
|
237
|
+
val key = keys.next()
|
|
238
|
+
val value = extras.get(key)
|
|
239
|
+
|
|
240
|
+
when (value) {
|
|
241
|
+
is String -> intent.putExtra(key, value)
|
|
242
|
+
is Int -> intent.putExtra(key, value)
|
|
243
|
+
is Long -> intent.putExtra(key, value)
|
|
244
|
+
is Double -> intent.putExtra(key, value)
|
|
245
|
+
is Boolean -> intent.putExtra(key, value)
|
|
246
|
+
is JSONArray -> {
|
|
247
|
+
val strArr = Array(value.length()) { i -> value.getString(i) }
|
|
248
|
+
intent.putExtra(key, strArr)
|
|
249
|
+
}
|
|
250
|
+
is JSONObject -> {
|
|
251
|
+
val bundle = jsonToBundle(value)
|
|
252
|
+
intent.putExtra(key, bundle)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
@Throws(JSONException::class)
|
|
259
|
+
private fun jsonToBundle(json: JSONObject): Bundle {
|
|
260
|
+
val bundle = Bundle()
|
|
261
|
+
val keys = json.keys()
|
|
262
|
+
while (keys.hasNext()) {
|
|
263
|
+
val key = keys.next()
|
|
264
|
+
val value = json.get(key)
|
|
265
|
+
|
|
266
|
+
when (value) {
|
|
267
|
+
is String -> bundle.putString(key, value)
|
|
268
|
+
is Int -> bundle.putInt(key, value)
|
|
269
|
+
is Long -> bundle.putLong(key, value)
|
|
270
|
+
is Double -> bundle.putDouble(key, value)
|
|
271
|
+
is Boolean -> bundle.putBoolean(key, value)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return bundle
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
private fun intentToJson(intent: Intent?): JSObject {
|
|
278
|
+
val json = JSObject()
|
|
279
|
+
|
|
280
|
+
if (intent == null) {
|
|
281
|
+
return json
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
try {
|
|
285
|
+
json.put("action", intent.action)
|
|
286
|
+
|
|
287
|
+
val extras = intent.extras
|
|
288
|
+
if (extras != null) {
|
|
289
|
+
json.put("extras", bundleToJson(extras))
|
|
290
|
+
}
|
|
291
|
+
} catch (e: Exception) {
|
|
292
|
+
Log.e(TAG, "intentToJson failed", e)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return json
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private fun bundleToJson(bundle: Bundle?): JSObject {
|
|
299
|
+
val json = JSObject()
|
|
300
|
+
|
|
301
|
+
if (bundle == null) {
|
|
302
|
+
return json
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
for (key in bundle.keySet()) {
|
|
306
|
+
try {
|
|
307
|
+
val value = bundle.get(key)
|
|
308
|
+
|
|
309
|
+
when (value) {
|
|
310
|
+
null -> json.put(key, JSONObject.NULL)
|
|
311
|
+
is String -> json.put(key, value)
|
|
312
|
+
is Int -> json.put(key, value)
|
|
313
|
+
is Long -> json.put(key, value)
|
|
314
|
+
is Double -> json.put(key, value)
|
|
315
|
+
is Float -> json.put(key, value.toDouble())
|
|
316
|
+
is Boolean -> json.put(key, value)
|
|
317
|
+
is Bundle -> json.put(key, bundleToJson(value))
|
|
318
|
+
is Array<*> -> {
|
|
319
|
+
if (value.isArrayOf<String>()) {
|
|
320
|
+
val arr = JSArray()
|
|
321
|
+
@Suppress("UNCHECKED_CAST")
|
|
322
|
+
for (s in value as Array<String>) {
|
|
323
|
+
arr.put(s)
|
|
324
|
+
}
|
|
325
|
+
json.put(key, arr)
|
|
326
|
+
} else if (value.isArrayOf<Parcelable>()) {
|
|
327
|
+
val arr = JSArray()
|
|
328
|
+
@Suppress("UNCHECKED_CAST")
|
|
329
|
+
for (p in value as Array<Parcelable>) {
|
|
330
|
+
arr.put(p.toString())
|
|
331
|
+
}
|
|
332
|
+
json.put(key, arr)
|
|
333
|
+
} else {
|
|
334
|
+
json.put(key, value.toString())
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
is IntArray -> {
|
|
338
|
+
val arr = JSArray()
|
|
339
|
+
for (i in value) {
|
|
340
|
+
arr.put(i)
|
|
341
|
+
}
|
|
342
|
+
json.put(key, arr)
|
|
343
|
+
}
|
|
344
|
+
is Parcelable -> json.put(key, value.toString())
|
|
345
|
+
else -> json.put(key, value.toString())
|
|
346
|
+
}
|
|
347
|
+
} catch (e: Exception) {
|
|
348
|
+
Log.w(TAG, "bundleToJson key failed: $key", e)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return json
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
override fun handleOnDestroy() {
|
|
356
|
+
for (receiver in receivers.values) {
|
|
357
|
+
try {
|
|
358
|
+
context.unregisterReceiver(receiver)
|
|
359
|
+
} catch (ignored: Exception) {
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
receivers.clear()
|
|
363
|
+
super.handleOnDestroy()
|
|
364
|
+
}
|
|
365
|
+
}
|
package/dist/Intent.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from "@capacitor/core";
|
|
2
|
+
import type { IntentResult, StartActivityForResultOptions, StartActivityForResultResult } from "./IntentPlugin";
|
|
3
|
+
/**
|
|
4
|
+
* Android 인텐트 플러그인
|
|
5
|
+
* - 브로드캐스트 송수신, 실행 인텐트 조회
|
|
6
|
+
* - 산업용 디바이스 연동용 (바코드 스캐너, PDA 등)
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class Intent {
|
|
9
|
+
/**
|
|
10
|
+
* 브로드캐스트 수신기 등록
|
|
11
|
+
* @returns 구독 해제 함수
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const unsub = await Intent.subscribe(
|
|
16
|
+
* ["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
17
|
+
* (result) => console.log(result.extras)
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* // 구독 해제
|
|
21
|
+
* unsub();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
static subscribe(filters: string[], callback: (result: IntentResult) => void): Promise<() => Promise<void>>;
|
|
25
|
+
/**
|
|
26
|
+
* 모든 브로드캐스트 수신기 구독 해제
|
|
27
|
+
*/
|
|
28
|
+
static unsubscribeAll(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* 브로드캐스트 전송
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* await Intent.send({
|
|
35
|
+
* action: "com.symbol.datawedge.api.ACTION",
|
|
36
|
+
* extras: {
|
|
37
|
+
* "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING"
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
static send(options: {
|
|
43
|
+
action: string;
|
|
44
|
+
extras?: Record<string, unknown>;
|
|
45
|
+
}): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* 실행 인텐트 조회
|
|
48
|
+
*/
|
|
49
|
+
static getLaunchIntent(): Promise<IntentResult>;
|
|
50
|
+
/**
|
|
51
|
+
* 이벤트 리스너 등록
|
|
52
|
+
* @returns 리스너 핸들 (handle.remove()로 해제)
|
|
53
|
+
*/
|
|
54
|
+
static addListener(eventName: "newIntent", callback: (result: IntentResult) => void): Promise<PluginListenerHandle>;
|
|
55
|
+
/**
|
|
56
|
+
* 모든 이벤트 리스너 제거
|
|
57
|
+
*/
|
|
58
|
+
static removeAllListeners(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* startActivityForResult로 외부 Activity를 실행하고 결과를 수신한다
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const result = await Intent.startActivityForResult({
|
|
65
|
+
* action: "com.example.PAY",
|
|
66
|
+
* extras: { amount: 1000 },
|
|
67
|
+
* });
|
|
68
|
+
* if (result.resultCode === -1) {
|
|
69
|
+
* // RESULT_OK
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
static startActivityForResult(options: StartActivityForResultOptions): Promise<StartActivityForResultResult>;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=Intent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Intent.d.ts","sourceRoot":"","sources":["../src/Intent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,KAAK,EAEV,YAAY,EACZ,6BAA6B,EAC7B,4BAA4B,EAC7B,MAAM,gBAAgB,CAAC;AASxB;;;;GAIG;AACH,8BAAsB,MAAM;IAC1B;;;;;;;;;;;;;;OAcG;WACU,SAAS,CACpB,OAAO,EAAE,MAAM,EAAE,EACjB,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GACvC,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAY/B;;OAEG;WACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5C;;;;;;;;;;;;OAYG;WACU,IAAI,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/F;;OAEG;WACU,eAAe,IAAI,OAAO,CAAC,YAAY,CAAC;IAIrD;;;OAGG;WACU,WAAW,CACtB,SAAS,EAAE,WAAW,EACtB,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GACvC,OAAO,CAAC,oBAAoB,CAAC;IAIhC;;OAEG;WACU,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhD;;;;;;;;;;;;;OAaG;WACU,sBAAsB,CACjC,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,4BAA4B,CAAC;CAGzC"}
|
package/dist/Intent.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { registerPlugin } from "@capacitor/core";
|
|
2
|
+
const intentPlugin = registerPlugin("Intent", {
|
|
3
|
+
web: async () => {
|
|
4
|
+
const { IntentWeb } = await import("./web/IntentWeb.js");
|
|
5
|
+
return new IntentWeb();
|
|
6
|
+
},
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* Android 인텐트 플러그인
|
|
10
|
+
* - 브로드캐스트 송수신, 실행 인텐트 조회
|
|
11
|
+
* - 산업용 디바이스 연동용 (바코드 스캐너, PDA 등)
|
|
12
|
+
*/
|
|
13
|
+
export class Intent {
|
|
14
|
+
/**
|
|
15
|
+
* 브로드캐스트 수신기 등록
|
|
16
|
+
* @returns 구독 해제 함수
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const unsub = await Intent.subscribe(
|
|
21
|
+
* ["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
22
|
+
* (result) => console.log(result.extras)
|
|
23
|
+
* );
|
|
24
|
+
*
|
|
25
|
+
* // 구독 해제
|
|
26
|
+
* unsub();
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
static async subscribe(filters, callback) {
|
|
30
|
+
const { id } = await intentPlugin.subscribe({ filters }, (result) => {
|
|
31
|
+
// { id }만 포함된 초기 resolve를 필터링
|
|
32
|
+
if (result.action != null) {
|
|
33
|
+
callback(result);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return async () => {
|
|
37
|
+
await intentPlugin.unsubscribe({ id });
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 모든 브로드캐스트 수신기 구독 해제
|
|
42
|
+
*/
|
|
43
|
+
static async unsubscribeAll() {
|
|
44
|
+
await intentPlugin.unsubscribeAll();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 브로드캐스트 전송
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* await Intent.send({
|
|
52
|
+
* action: "com.symbol.datawedge.api.ACTION",
|
|
53
|
+
* extras: {
|
|
54
|
+
* "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING"
|
|
55
|
+
* }
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
static async send(options) {
|
|
60
|
+
await intentPlugin.send(options);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 실행 인텐트 조회
|
|
64
|
+
*/
|
|
65
|
+
static async getLaunchIntent() {
|
|
66
|
+
return intentPlugin.getLaunchIntent();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 이벤트 리스너 등록
|
|
70
|
+
* @returns 리스너 핸들 (handle.remove()로 해제)
|
|
71
|
+
*/
|
|
72
|
+
static async addListener(eventName, callback) {
|
|
73
|
+
return intentPlugin.addListener(eventName, callback);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 모든 이벤트 리스너 제거
|
|
77
|
+
*/
|
|
78
|
+
static async removeAllListeners() {
|
|
79
|
+
await intentPlugin.removeAllListeners();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* startActivityForResult로 외부 Activity를 실행하고 결과를 수신한다
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const result = await Intent.startActivityForResult({
|
|
87
|
+
* action: "com.example.PAY",
|
|
88
|
+
* extras: { amount: 1000 },
|
|
89
|
+
* });
|
|
90
|
+
* if (result.resultCode === -1) {
|
|
91
|
+
* // RESULT_OK
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
static async startActivityForResult(options) {
|
|
96
|
+
return intentPlugin.startActivityForResult(options);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=Intent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Intent.js","sourceRoot":"","sources":["../src/Intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AASjD,MAAM,YAAY,GAAG,cAAc,CAAe,QAAQ,EAAE;IAC1D,GAAG,EAAE,KAAK,IAAI,EAAE;QACd,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC;QACtD,OAAO,IAAI,SAAS,EAAE,CAAC;IACzB,CAAC;CACF,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,OAAgB,MAAM;IAC1B;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,KAAK,CAAC,SAAS,CACpB,OAAiB,EACjB,QAAwC;QAExC,MAAM,EAAE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브로드캐스트 액션 */
|
|
4
|
+
action?: string;
|
|
5
|
+
/** 추가 데이터 */
|
|
6
|
+
extras?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export interface StartActivityForResultOptions {
|
|
9
|
+
action?: string;
|
|
10
|
+
uri?: string;
|
|
11
|
+
extras?: Record<string, unknown>;
|
|
12
|
+
/** MIME type */
|
|
13
|
+
type?: string;
|
|
14
|
+
/** 특정 앱 지정 */
|
|
15
|
+
packageName?: string;
|
|
16
|
+
/** 특정 Activity 지정 */
|
|
17
|
+
className?: string;
|
|
18
|
+
/** Intent flags */
|
|
19
|
+
flags?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface StartActivityForResultResult {
|
|
22
|
+
resultCode: number;
|
|
23
|
+
data?: {
|
|
24
|
+
action?: string;
|
|
25
|
+
uri?: string;
|
|
26
|
+
extras?: Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface IntentPlugin {
|
|
30
|
+
/**
|
|
31
|
+
* 브로드캐스트 수신기 등록
|
|
32
|
+
*/
|
|
33
|
+
subscribe(options: {
|
|
34
|
+
filters: string[];
|
|
35
|
+
}, callback: (result: IntentResult) => void): Promise<{
|
|
36
|
+
id: string;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* 특정 브로드캐스트 수신기 구독 해제
|
|
40
|
+
*/
|
|
41
|
+
unsubscribe(options: {
|
|
42
|
+
id: string;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* 모든 브로드캐스트 수신기 구독 해제
|
|
46
|
+
*/
|
|
47
|
+
unsubscribeAll(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* 브로드캐스트 전송
|
|
50
|
+
*/
|
|
51
|
+
send(options: {
|
|
52
|
+
action: string;
|
|
53
|
+
extras?: Record<string, unknown>;
|
|
54
|
+
}): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* 실행 인텐트 조회
|
|
57
|
+
*/
|
|
58
|
+
getLaunchIntent(): Promise<IntentResult>;
|
|
59
|
+
/**
|
|
60
|
+
* 앱 실행 중 수신되는 새 인텐트에 대한 리스너 등록
|
|
61
|
+
*/
|
|
62
|
+
addListener(eventName: "newIntent", listenerFunc: (data: IntentResult) => void): Promise<PluginListenerHandle>;
|
|
63
|
+
/**
|
|
64
|
+
* 모든 이벤트 리스너 제거
|
|
65
|
+
*/
|
|
66
|
+
removeAllListeners(): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* startActivityForResult로 외부 Activity를 실행하고 결과를 수신한다
|
|
69
|
+
*/
|
|
70
|
+
startActivityForResult(options: StartActivityForResultOptions): Promise<StartActivityForResultResult>;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=IntentPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntentPlugin.d.ts","sourceRoot":"","sources":["../src/IntentPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,MAAM,WAAW,YAAY;IAC3B,gBAAgB;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa;IACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,6BAA6B;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,gBAAgB;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,4BAA4B;IAC3C,UAAU,EAAE,M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.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM;AACN,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { WebPlugin } from "@capacitor/core";
|
|
2
|
+
import type { IntentPlugin, IntentResult, StartActivityForResultOptions, StartActivityForResultResult } from "../IntentPlugin";
|
|
3
|
+
export declare class IntentWeb extends WebPlugin implements IntentPlugin {
|
|
4
|
+
private static readonly _warn;
|
|
5
|
+
subscribe(_options: {
|
|
6
|
+
filters: string[];
|
|
7
|
+
}, _callback: (result: IntentResult) => void): Promise<{
|
|
8
|
+
id: string;
|
|
9
|
+
}>;
|
|
10
|
+
unsubscribe(_options: {
|
|
11
|
+
id: string;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
unsubscribeAll(): Promise<void>;
|
|
14
|
+
send(_options: {
|
|
15
|
+
action: string;
|
|
16
|
+
extras?: Record<string, unknown>;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
getLaunchIntent(): Promise<IntentResult>;
|
|
19
|
+
startActivityForResult(_options: StartActivityForResultOptions): Promise<StartActivityForResultResult>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=IntentWeb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntentWeb.d.ts","sourceRoot":"","sources":["../../src/web/IntentWeb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,6BAA6B,EAC7B,4BAA4B,EAC7B,MAAM,iBAAiB,CAAC;AAEzB,qBAAa,SAAU,SAAQ,SAAU,YAAW,YAAY;IAC9D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAEiB;IAE9C,SAAS,CACP,QAAQ,EAAE;QAAE,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAC/B,SAAS,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GACxC,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAKpB,WAAW,CAAC,QAAQ,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrC,IAAI,CAAC,QAAQ,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKnF,eAAe,IAAI,OAAO,CAAC,YAAY,CAAC;IAIxC,sBAAsB,CACpB,QAAQ,EAAE,6BAA6B,GACtC,OAAO,CAAC,4BAA4B,CAAC;CAIzC"}
|