@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
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WebPlugin } from "@capacitor/core";
|
|
2
|
+
export class IntentWeb extends WebPlugin {
|
|
3
|
+
static _warn = () =>
|
|
4
|
+
// eslint-disable-next-line no-console
|
|
5
|
+
console.warn("[Intent] 웹 환경에서는 지원하지 않습니다.");
|
|
6
|
+
subscribe(_options, _callback) {
|
|
7
|
+
IntentWeb._warn();
|
|
8
|
+
return Promise.resolve({ id: "web-stub" });
|
|
9
|
+
}
|
|
10
|
+
async unsubscribe(_options) {
|
|
11
|
+
// 웹에서는 동작 없음
|
|
12
|
+
}
|
|
13
|
+
async unsubscribeAll() {
|
|
14
|
+
// 웹에서는 동작 없음
|
|
15
|
+
}
|
|
16
|
+
send(_options) {
|
|
17
|
+
IntentWeb._warn();
|
|
18
|
+
return Promise.resolve();
|
|
19
|
+
}
|
|
20
|
+
getLaunchIntent() {
|
|
21
|
+
return Promise.resolve({});
|
|
22
|
+
}
|
|
23
|
+
startActivityForResult(_options) {
|
|
24
|
+
IntentWeb._warn();
|
|
25
|
+
return Promise.resolve({ resultCode: 0 });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=IntentWeb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntentWeb.js","sourceRoot":"","sources":["../../src/web/IntentWeb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,MAAM,OAAO,SAAU,SAAQ,SAAS;IAC9B,MAAM,CAAU,KAAK,GAAG,GAAG,EAAE;IACnC,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;IAE9C,SAAS,CACP,QAA+B,EAC/B,SAAyC;QAEzC,SAAS,CAAC,KAAK,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,QAAwB;QACxC,aAAa;IACf,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,aAAa;IACf,CAAC;IAED,IAAI,CAAC,QAA8D;QACjE,SAAS,CAAC,KAAK,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,eAAe;QACb,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,sBAAsB,CACpB,QAAuC;QAEvC,SAAS,CAAC,KAAK,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/capacitor-plugin-intent",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "심플리즘 패키지 - Capacitor Intent
|
|
5
|
-
"author": "
|
|
3
|
+
"version": "14.0.1",
|
|
4
|
+
"description": "심플리즘 패키지 - Capacitor Intent 플러그인",
|
|
5
|
+
"author": "심플리즘",
|
|
6
|
+
"license": "Apache-2.0",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
9
|
"url": "https://github.com/kslhunter/simplysm.git",
|
|
9
10
|
"directory": "packages/capacitor-plugin-intent"
|
|
10
11
|
},
|
|
11
|
-
"license": "MIT",
|
|
12
12
|
"type": "module",
|
|
13
13
|
"main": "./dist/index.js",
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"android"
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@capacitor/core": "^7.6.0"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@capacitor/core": "^7"
|
|
25
|
+
},
|
|
15
26
|
"capacitor": {
|
|
16
27
|
"android": {
|
|
17
28
|
"src": "android"
|
|
18
29
|
}
|
|
19
|
-
},
|
|
20
|
-
"peerDependencies": {
|
|
21
|
-
"@capacitor/core": "^7.4.4"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"@capacitor/core": "^7.6.0"
|
|
25
30
|
}
|
|
26
31
|
}
|
package/src/Intent.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { registerPlugin } from "@capacitor/core";
|
|
2
|
-
import {
|
|
2
|
+
import type { PluginListenerHandle } from "@capacitor/core";
|
|
3
|
+
import type {
|
|
4
|
+
IntentPlugin,
|
|
5
|
+
IntentResult,
|
|
6
|
+
StartActivityForResultOptions,
|
|
7
|
+
StartActivityForResultResult,
|
|
8
|
+
} from "./IntentPlugin";
|
|
3
9
|
|
|
4
|
-
const
|
|
10
|
+
const intentPlugin = registerPlugin<IntentPlugin>("Intent", {
|
|
5
11
|
web: async () => {
|
|
6
12
|
const { IntentWeb } = await import("./web/IntentWeb");
|
|
7
13
|
return new IntentWeb();
|
|
@@ -9,13 +15,14 @@ const IntentPlugin = registerPlugin<IIntentPlugin>("Intent", {
|
|
|
9
15
|
});
|
|
10
16
|
|
|
11
17
|
/**
|
|
12
|
-
* Android
|
|
13
|
-
* -
|
|
18
|
+
* Android 인텐트 플러그인
|
|
19
|
+
* - 브로드캐스트 송수신, 실행 인텐트 조회
|
|
20
|
+
* - 산업용 디바이스 연동용 (바코드 스캐너, PDA 등)
|
|
14
21
|
*/
|
|
15
22
|
export abstract class Intent {
|
|
16
23
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @returns 해제 함수
|
|
24
|
+
* 브로드캐스트 수신기 등록
|
|
25
|
+
* @returns 구독 해제 함수
|
|
19
26
|
*
|
|
20
27
|
* @example
|
|
21
28
|
* ```ts
|
|
@@ -24,29 +31,34 @@ export abstract class Intent {
|
|
|
24
31
|
* (result) => console.log(result.extras)
|
|
25
32
|
* );
|
|
26
33
|
*
|
|
27
|
-
* // 해제
|
|
34
|
+
* // 구독 해제
|
|
28
35
|
* unsub();
|
|
29
36
|
* ```
|
|
30
37
|
*/
|
|
31
38
|
static async subscribe(
|
|
32
39
|
filters: string[],
|
|
33
|
-
callback: (result:
|
|
40
|
+
callback: (result: IntentResult) => void,
|
|
34
41
|
): Promise<() => Promise<void>> {
|
|
35
|
-
const { id } = await
|
|
42
|
+
const { id } = await intentPlugin.subscribe({ filters }, (result) => {
|
|
43
|
+
// { id }만 포함된 초기 resolve를 필터링
|
|
44
|
+
if (result.action != null) {
|
|
45
|
+
callback(result);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
36
48
|
return async () => {
|
|
37
|
-
await
|
|
49
|
+
await intentPlugin.unsubscribe({ id });
|
|
38
50
|
};
|
|
39
51
|
}
|
|
40
52
|
|
|
41
53
|
/**
|
|
42
|
-
* 모든
|
|
54
|
+
* 모든 브로드캐스트 수신기 구독 해제
|
|
43
55
|
*/
|
|
44
56
|
static async unsubscribeAll(): Promise<void> {
|
|
45
|
-
await
|
|
57
|
+
await intentPlugin.unsubscribeAll();
|
|
46
58
|
}
|
|
47
59
|
|
|
48
60
|
/**
|
|
49
|
-
*
|
|
61
|
+
* 브로드캐스트 전송
|
|
50
62
|
*
|
|
51
63
|
* @example
|
|
52
64
|
* ```ts
|
|
@@ -59,32 +71,51 @@ export abstract class Intent {
|
|
|
59
71
|
* ```
|
|
60
72
|
*/
|
|
61
73
|
static async send(options: { action: string; extras?: Record<string, unknown> }): Promise<void> {
|
|
62
|
-
await
|
|
74
|
+
await intentPlugin.send(options);
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
/**
|
|
66
|
-
*
|
|
78
|
+
* 실행 인텐트 조회
|
|
67
79
|
*/
|
|
68
|
-
static async getLaunchIntent(): Promise<
|
|
69
|
-
return
|
|
80
|
+
static async getLaunchIntent(): Promise<IntentResult> {
|
|
81
|
+
return intentPlugin.getLaunchIntent();
|
|
70
82
|
}
|
|
71
83
|
|
|
72
84
|
/**
|
|
73
|
-
*
|
|
85
|
+
* 이벤트 리스너 등록
|
|
86
|
+
* @returns 리스너 핸들 (handle.remove()로 해제)
|
|
87
|
+
*/
|
|
88
|
+
static async addListener(
|
|
89
|
+
eventName: "newIntent",
|
|
90
|
+
callback: (result: IntentResult) => void,
|
|
91
|
+
): Promise<PluginListenerHandle> {
|
|
92
|
+
return intentPlugin.addListener(eventName, callback);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 모든 이벤트 리스너 제거
|
|
97
|
+
*/
|
|
98
|
+
static async removeAllListeners(): Promise<void> {
|
|
99
|
+
await intentPlugin.removeAllListeners();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* startActivityForResult로 외부 Activity를 실행하고 결과를 수신한다
|
|
74
104
|
*
|
|
75
105
|
* @example
|
|
76
106
|
* ```ts
|
|
77
107
|
* const result = await Intent.startActivityForResult({
|
|
78
|
-
* action: "
|
|
79
|
-
*
|
|
108
|
+
* action: "com.example.PAY",
|
|
109
|
+
* extras: { amount: 1000 },
|
|
80
110
|
* });
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* console.log("Selected:", result.data);
|
|
111
|
+
* if (result.resultCode === -1) {
|
|
112
|
+
* // RESULT_OK
|
|
84
113
|
* }
|
|
85
114
|
* ```
|
|
86
115
|
*/
|
|
87
|
-
static async startActivityForResult(
|
|
88
|
-
|
|
116
|
+
static async startActivityForResult(
|
|
117
|
+
options: StartActivityForResultOptions,
|
|
118
|
+
): Promise<StartActivityForResultResult> {
|
|
119
|
+
return intentPlugin.startActivityForResult(options);
|
|
89
120
|
}
|
|
90
121
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from "@capacitor/core";
|
|
2
|
+
|
|
3
|
+
export interface IntentResult {
|
|
4
|
+
/** 브로드캐스트 액션 */
|
|
5
|
+
action?: string;
|
|
6
|
+
/** 추가 데이터 */
|
|
7
|
+
extras?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface StartActivityForResultOptions {
|
|
11
|
+
action?: string;
|
|
12
|
+
uri?: string;
|
|
13
|
+
extras?: Record<string, unknown>;
|
|
14
|
+
/** MIME type */
|
|
15
|
+
type?: string;
|
|
16
|
+
/** 특정 앱 지정 */
|
|
17
|
+
packageName?: string;
|
|
18
|
+
/** 특정 Activity 지정 */
|
|
19
|
+
className?: string;
|
|
20
|
+
/** Intent flags */
|
|
21
|
+
flags?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface StartActivityForResultResult {
|
|
25
|
+
resultCode: number;
|
|
26
|
+
data?: {
|
|
27
|
+
action?: string;
|
|
28
|
+
uri?: string;
|
|
29
|
+
extras?: Record<string, unknown>;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface IntentPlugin {
|
|
34
|
+
/**
|
|
35
|
+
* 브로드캐스트 수신기 등록
|
|
36
|
+
*/
|
|
37
|
+
subscribe(
|
|
38
|
+
options: { filters: string[] },
|
|
39
|
+
callback: (result: IntentResult) => void,
|
|
40
|
+
): Promise<{ id: string }>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 특정 브로드캐스트 수신기 구독 해제
|
|
44
|
+
*/
|
|
45
|
+
unsubscribe(options: { id: string }): Promise<void>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 모든 브로드캐스트 수신기 구독 해제
|
|
49
|
+
*/
|
|
50
|
+
unsubscribeAll(): Promise<void>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 브로드캐스트 전송
|
|
54
|
+
*/
|
|
55
|
+
send(options: { action: string; extras?: Record<string, unknown> }): Promise<void>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 실행 인텐트 조회
|
|
59
|
+
*/
|
|
60
|
+
getLaunchIntent(): Promise<IntentResult>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 앱 실행 중 수신되는 새 인텐트에 대한 리스너 등록
|
|
64
|
+
*/
|
|
65
|
+
addListener(
|
|
66
|
+
eventName: "newIntent",
|
|
67
|
+
listenerFunc: (data: IntentResult) => void,
|
|
68
|
+
): Promise<PluginListenerHandle>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 모든 이벤트 리스너 제거
|
|
72
|
+
*/
|
|
73
|
+
removeAllListeners(): Promise<void>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* startActivityForResult로 외부 Activity를 실행하고 결과를 수신한다
|
|
77
|
+
*/
|
|
78
|
+
startActivityForResult(
|
|
79
|
+
options: StartActivityForResultOptions,
|
|
80
|
+
): Promise<StartActivityForResultResult>;
|
|
81
|
+
}
|
package/src/index.ts
CHANGED
package/src/web/IntentWeb.ts
CHANGED
|
@@ -1,34 +1,45 @@
|
|
|
1
1
|
import { WebPlugin } from "@capacitor/core";
|
|
2
|
-
import {
|
|
2
|
+
import type {
|
|
3
|
+
IntentPlugin,
|
|
4
|
+
IntentResult,
|
|
5
|
+
StartActivityForResultOptions,
|
|
6
|
+
StartActivityForResultResult,
|
|
7
|
+
} from "../IntentPlugin";
|
|
3
8
|
|
|
4
|
-
export class IntentWeb extends WebPlugin implements
|
|
5
|
-
|
|
9
|
+
export class IntentWeb extends WebPlugin implements IntentPlugin {
|
|
10
|
+
private static readonly _warn = () =>
|
|
11
|
+
// eslint-disable-next-line no-console
|
|
12
|
+
console.warn("[Intent] 웹 환경에서는 지원하지 않습니다.");
|
|
13
|
+
|
|
14
|
+
subscribe(
|
|
6
15
|
_options: { filters: string[] },
|
|
7
|
-
_callback: (result:
|
|
16
|
+
_callback: (result: IntentResult) => void,
|
|
8
17
|
): Promise<{ id: string }> {
|
|
9
|
-
|
|
10
|
-
return
|
|
18
|
+
IntentWeb._warn();
|
|
19
|
+
return Promise.resolve({ id: "web-stub" });
|
|
11
20
|
}
|
|
12
21
|
|
|
13
22
|
async unsubscribe(_options: { id: string }): Promise<void> {
|
|
14
|
-
|
|
23
|
+
// 웹에서는 동작 없음
|
|
15
24
|
}
|
|
16
25
|
|
|
17
26
|
async unsubscribeAll(): Promise<void> {
|
|
18
|
-
|
|
27
|
+
// 웹에서는 동작 없음
|
|
19
28
|
}
|
|
20
29
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
send(_options: { action: string; extras?: Record<string, unknown> }): Promise<void> {
|
|
31
|
+
IntentWeb._warn();
|
|
32
|
+
return Promise.resolve();
|
|
24
33
|
}
|
|
25
34
|
|
|
26
|
-
|
|
27
|
-
return
|
|
35
|
+
getLaunchIntent(): Promise<IntentResult> {
|
|
36
|
+
return Promise.resolve({});
|
|
28
37
|
}
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
startActivityForResult(
|
|
40
|
+
_options: StartActivityForResultOptions,
|
|
41
|
+
): Promise<StartActivityForResultResult> {
|
|
42
|
+
IntentWeb._warn();
|
|
43
|
+
return Promise.resolve({ resultCode: 0 });
|
|
33
44
|
}
|
|
34
45
|
}
|
package/README.md
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
# @simplysm/capacitor-plugin-intent
|
|
2
|
-
|
|
3
|
-
Capacitor Intent Plugin -- Android intent send/receive for industrial devices (barcode scanners, PDA, etc.). Provides subscription-based intent receiving, intent sending with extras, launch intent retrieval, and startActivityForResult support.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @simplysm/capacitor-plugin-intent
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## API Overview
|
|
12
|
-
|
|
13
|
-
| API | Type | Description |
|
|
14
|
-
|-----|------|-------------|
|
|
15
|
-
| `Intent` | Abstract class | Static methods for subscribing to, sending, and managing Android intents |
|
|
16
|
-
| `IIntentResult` | Interface | Intent result containing action and extras |
|
|
17
|
-
| `IStartActivityForResultOptions` | Interface | Options for starting an activity for result |
|
|
18
|
-
| `IActivityResult` | Interface | Activity result containing resultCode, data, and extras |
|
|
19
|
-
| `IIntentPlugin` | Interface | Low-level Capacitor plugin interface for intent operations |
|
|
20
|
-
|
|
21
|
-
## API Reference
|
|
22
|
-
|
|
23
|
-
### `IIntentResult`
|
|
24
|
-
|
|
25
|
-
Result object received from an intent or launch intent.
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
export interface IIntentResult {
|
|
29
|
-
action?: string;
|
|
30
|
-
extras?: Record<string, unknown>;
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
| Field | Type | Description |
|
|
35
|
-
|-------|------|-------------|
|
|
36
|
-
| `action` | `string \| undefined` | The intent action string |
|
|
37
|
-
| `extras` | `Record<string, unknown> \| undefined` | Extra data attached to the intent |
|
|
38
|
-
|
|
39
|
-
### `IStartActivityForResultOptions`
|
|
40
|
-
|
|
41
|
-
Options for starting an activity and receiving its result.
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
export interface IStartActivityForResultOptions {
|
|
45
|
-
action: string;
|
|
46
|
-
uri?: string;
|
|
47
|
-
extras?: Record<string, unknown>;
|
|
48
|
-
package?: string;
|
|
49
|
-
component?: string;
|
|
50
|
-
type?: string;
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
| Field | Type | Description |
|
|
55
|
-
|-------|------|-------------|
|
|
56
|
-
| `action` | `string` | Intent action (required) |
|
|
57
|
-
| `uri` | `string \| undefined` | Data URI |
|
|
58
|
-
| `extras` | `Record<string, unknown> \| undefined` | Extra data to include in the intent |
|
|
59
|
-
| `package` | `string \| undefined` | Target package name |
|
|
60
|
-
| `component` | `string \| undefined` | Target component class name (requires `package`) |
|
|
61
|
-
| `type` | `string \| undefined` | MIME type |
|
|
62
|
-
|
|
63
|
-
### `IActivityResult`
|
|
64
|
-
|
|
65
|
-
Result returned from a started activity.
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
export interface IActivityResult {
|
|
69
|
-
resultCode: number;
|
|
70
|
-
data?: string;
|
|
71
|
-
extras?: Record<string, unknown>;
|
|
72
|
-
}
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
| Field | Type | Description |
|
|
76
|
-
|-------|------|-------------|
|
|
77
|
-
| `resultCode` | `number` | Activity result code (`RESULT_OK = -1`, `RESULT_CANCELED = 0`) |
|
|
78
|
-
| `data` | `string \| undefined` | Result data URI |
|
|
79
|
-
| `extras` | `Record<string, unknown> \| undefined` | Result extras |
|
|
80
|
-
|
|
81
|
-
### `IIntentPlugin`
|
|
82
|
-
|
|
83
|
-
Low-level Capacitor plugin interface. Use `Intent` instead for a simplified API.
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
export interface IIntentPlugin {
|
|
87
|
-
subscribe(
|
|
88
|
-
options: { filters: string[] },
|
|
89
|
-
callback: (result: IIntentResult) => void,
|
|
90
|
-
): Promise<{ id: string }>;
|
|
91
|
-
unsubscribe(options: { id: string }): Promise<void>;
|
|
92
|
-
unsubscribeAll(): Promise<void>;
|
|
93
|
-
send(options: { action: string; extras?: Record<string, unknown> }): Promise<void>;
|
|
94
|
-
getLaunchIntent(): Promise<IIntentResult>;
|
|
95
|
-
startActivityForResult(options: IStartActivityForResultOptions): Promise<IActivityResult>;
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
| Method | Parameters | Returns | Description |
|
|
100
|
-
|--------|------------|---------|-------------|
|
|
101
|
-
| `subscribe` | `options: { filters: string[] }, callback` | `Promise<{ id: string }>` | Register an intent receiver with action filters |
|
|
102
|
-
| `unsubscribe` | `options: { id: string }` | `Promise<void>` | Remove a specific intent receiver by ID |
|
|
103
|
-
| `unsubscribeAll` | -- | `Promise<void>` | Remove all intent receivers |
|
|
104
|
-
| `send` | `options: { action, extras? }` | `Promise<void>` | Send an intent with action and optional extras |
|
|
105
|
-
| `getLaunchIntent` | -- | `Promise<IIntentResult>` | Get the intent that launched the app |
|
|
106
|
-
| `startActivityForResult` | `options: IStartActivityForResultOptions` | `Promise<IActivityResult>` | Start an activity and receive its result |
|
|
107
|
-
|
|
108
|
-
### `Intent`
|
|
109
|
-
|
|
110
|
-
Abstract class with static methods for Android intent send/receive. Designed for industrial device integration (barcode scanners, PDA, etc.).
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
export abstract class Intent {
|
|
114
|
-
static async subscribe(
|
|
115
|
-
filters: string[],
|
|
116
|
-
callback: (result: IIntentResult) => void,
|
|
117
|
-
): Promise<() => Promise<void>>;
|
|
118
|
-
|
|
119
|
-
static async unsubscribeAll(): Promise<void>;
|
|
120
|
-
|
|
121
|
-
static async send(options: {
|
|
122
|
-
action: string;
|
|
123
|
-
extras?: Record<string, unknown>;
|
|
124
|
-
}): Promise<void>;
|
|
125
|
-
|
|
126
|
-
static async getLaunchIntent(): Promise<IIntentResult>;
|
|
127
|
-
|
|
128
|
-
static async startActivityForResult(
|
|
129
|
-
options: IStartActivityForResultOptions,
|
|
130
|
-
): Promise<IActivityResult>;
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
| Method | Parameters | Returns | Description |
|
|
135
|
-
|--------|------------|---------|-------------|
|
|
136
|
-
| `subscribe` | `filters: string[], callback: (result: IIntentResult) => void` | `Promise<() => Promise<void>>` | Register an intent receiver; returns an unsubscribe function |
|
|
137
|
-
| `unsubscribeAll` | -- | `Promise<void>` | Remove all registered intent receivers |
|
|
138
|
-
| `send` | `options: { action: string; extras?: Record<string, unknown> }` | `Promise<void>` | Send an intent with action and optional extras |
|
|
139
|
-
| `getLaunchIntent` | -- | `Promise<IIntentResult>` | Retrieve the intent that launched the application |
|
|
140
|
-
| `startActivityForResult` | `options: IStartActivityForResultOptions` | `Promise<IActivityResult>` | Start an activity and receive its result |
|
|
141
|
-
|
|
142
|
-
## Usage Examples
|
|
143
|
-
|
|
144
|
-
### Subscribe to intents from a barcode scanner
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
import { Intent } from "@simplysm/capacitor-plugin-intent";
|
|
148
|
-
|
|
149
|
-
const unsubscribe = await Intent.subscribe(
|
|
150
|
-
["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
151
|
-
(result) => {
|
|
152
|
-
console.log("Action:", result.action);
|
|
153
|
-
console.log("Extras:", result.extras);
|
|
154
|
-
},
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
// Later, unsubscribe
|
|
158
|
-
await unsubscribe();
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Send an intent to trigger a scan
|
|
162
|
-
|
|
163
|
-
```typescript
|
|
164
|
-
import { Intent } from "@simplysm/capacitor-plugin-intent";
|
|
165
|
-
|
|
166
|
-
await Intent.send({
|
|
167
|
-
action: "com.symbol.datawedge.api.ACTION",
|
|
168
|
-
extras: {
|
|
169
|
-
"com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING",
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### Start an activity for result
|
|
175
|
-
|
|
176
|
-
```typescript
|
|
177
|
-
import { Intent } from "@simplysm/capacitor-plugin-intent";
|
|
178
|
-
|
|
179
|
-
const result = await Intent.startActivityForResult({
|
|
180
|
-
action: "android.intent.action.GET_CONTENT",
|
|
181
|
-
type: "image/*",
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
if (result.resultCode === -1) {
|
|
185
|
-
// RESULT_OK
|
|
186
|
-
console.log("Selected:", result.data);
|
|
187
|
-
}
|
|
188
|
-
```
|