capacitor-camera-module 0.0.3 → 0.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
CHANGED
|
@@ -13,7 +13,6 @@ npx cap sync
|
|
|
13
13
|
|
|
14
14
|
<docgen-index>
|
|
15
15
|
|
|
16
|
-
* [`echo(...)`](#echo)
|
|
17
16
|
* [`echo(...)`](#echo)
|
|
18
17
|
* [`checkPermission()`](#checkpermission)
|
|
19
18
|
* [`requestPermission()`](#requestpermission)
|
|
@@ -41,21 +40,6 @@ echo(options: { value: string; }) => Promise<{ value: string; }>
|
|
|
41
40
|
--------------------
|
|
42
41
|
|
|
43
42
|
|
|
44
|
-
### echo(...)
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
echo(options: { value: string; }) => Promise<{ value: string; }>
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
| Param | Type |
|
|
51
|
-
| ------------- | ------------------------------- |
|
|
52
|
-
| **`options`** | <code>{ value: string; }</code> |
|
|
53
|
-
|
|
54
|
-
**Returns:** <code>Promise<{ value: string; }></code>
|
|
55
|
-
|
|
56
|
-
--------------------
|
|
57
|
-
|
|
58
|
-
|
|
59
43
|
### checkPermission()
|
|
60
44
|
|
|
61
45
|
```typescript
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
package com.eddieagvictoria.cameramodule;
|
|
2
2
|
|
|
3
3
|
import android.Manifest;
|
|
4
|
-
import android.content.pm.PackageManager;
|
|
5
4
|
import android.os.Build;
|
|
5
|
+
import android.content.pm.PackageManager;
|
|
6
6
|
|
|
7
|
-
import androidx.activity.result.ActivityResultCallback;
|
|
8
|
-
import androidx.activity.result.ActivityResultLauncher;
|
|
9
|
-
import androidx.activity.result.contract.ActivityResultContracts;
|
|
10
|
-
import androidx.appcompat.app.AppCompatActivity;
|
|
11
7
|
import androidx.core.content.ContextCompat;
|
|
12
8
|
|
|
13
9
|
import com.getcapacitor.JSObject;
|
|
14
10
|
import com.getcapacitor.Plugin;
|
|
15
11
|
import com.getcapacitor.PluginCall;
|
|
16
12
|
import com.getcapacitor.PluginMethod;
|
|
13
|
+
import com.getcapacitor.PermissionState;
|
|
17
14
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
18
15
|
import com.getcapacitor.annotation.Permission;
|
|
16
|
+
import com.getcapacitor.annotation.PermissionCallback;
|
|
19
17
|
|
|
20
18
|
@CapacitorPlugin(
|
|
21
19
|
name = "CameraModule",
|
|
@@ -28,14 +26,6 @@ import com.getcapacitor.annotation.Permission;
|
|
|
28
26
|
)
|
|
29
27
|
public class CameraModulePlugin extends Plugin {
|
|
30
28
|
|
|
31
|
-
private static final String CAMERA_PERMISSION = Manifest.permission.CAMERA;
|
|
32
|
-
private PluginCall pendingPermissionCall = null;
|
|
33
|
-
|
|
34
|
-
@Override
|
|
35
|
-
public void load() {
|
|
36
|
-
super.load();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
29
|
@PluginMethod
|
|
40
30
|
public void echo(PluginCall call) {
|
|
41
31
|
String value = call.getString("value", "");
|
|
@@ -48,104 +38,77 @@ public class CameraModulePlugin extends Plugin {
|
|
|
48
38
|
public void checkPermission(PluginCall call) {
|
|
49
39
|
JSObject ret = new JSObject();
|
|
50
40
|
|
|
51
|
-
if (Build.VERSION.SDK_INT
|
|
52
|
-
int permissionStatus = ContextCompat.checkSelfPermission(
|
|
53
|
-
getContext(),
|
|
54
|
-
CAMERA_PERMISSION
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
boolean granted = permissionStatus == PackageManager.PERMISSION_GRANTED;
|
|
58
|
-
|
|
59
|
-
ret.put("granted", granted);
|
|
60
|
-
|
|
61
|
-
if (granted) {
|
|
62
|
-
ret.put("status", "granted");
|
|
63
|
-
} else {
|
|
64
|
-
if (getActivity() instanceof AppCompatActivity) {
|
|
65
|
-
boolean shouldShowRationale = ((AppCompatActivity) getActivity())
|
|
66
|
-
.shouldShowRequestPermissionRationale(CAMERA_PERMISSION);
|
|
67
|
-
|
|
68
|
-
if (shouldShowRationale) {
|
|
69
|
-
ret.put("status", "prompt-with-rationale");
|
|
70
|
-
} else {
|
|
71
|
-
ret.put("status", "prompt");
|
|
72
|
-
}
|
|
73
|
-
} else {
|
|
74
|
-
ret.put("status", "denied");
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
ret.put("details", "Android SDK " + Build.VERSION.SDK_INT);
|
|
79
|
-
|
|
80
|
-
} else {
|
|
81
|
-
// Para versiones anteriores a Android 6.0
|
|
41
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
|
82
42
|
ret.put("granted", true);
|
|
83
43
|
ret.put("status", "granted");
|
|
84
44
|
ret.put("details", "Pre-Marshmallow, granted at install");
|
|
45
|
+
call.resolve(ret);
|
|
46
|
+
return;
|
|
85
47
|
}
|
|
86
48
|
|
|
49
|
+
boolean granted =
|
|
50
|
+
ContextCompat.checkSelfPermission(
|
|
51
|
+
getContext(),
|
|
52
|
+
Manifest.permission.CAMERA
|
|
53
|
+
) == PackageManager.PERMISSION_GRANTED;
|
|
54
|
+
|
|
55
|
+
ret.put("granted", granted);
|
|
56
|
+
ret.put("status", granted ? "granted" : "prompt");
|
|
57
|
+
ret.put("details", "Android SDK " + Build.VERSION.SDK_INT);
|
|
58
|
+
|
|
87
59
|
call.resolve(ret);
|
|
88
60
|
}
|
|
89
61
|
|
|
90
62
|
@PluginMethod
|
|
91
63
|
public void requestPermission(PluginCall call) {
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// Registrar el callback para el permiso
|
|
96
|
-
ActivityResultLauncher<String> requestPermissionLauncher =
|
|
97
|
-
((AppCompatActivity) getActivity())
|
|
98
|
-
.registerForActivityResult(
|
|
99
|
-
new ActivityResultContracts.RequestPermission(),
|
|
100
|
-
isGranted -> {
|
|
101
|
-
if (pendingPermissionCall != null) {
|
|
102
|
-
JSObject result = new JSObject();
|
|
103
|
-
result.put("granted", isGranted);
|
|
104
|
-
result.put("status", isGranted ? "granted" : "denied");
|
|
105
|
-
result.put("details", "Permission request completed");
|
|
106
|
-
|
|
107
|
-
pendingPermissionCall.resolve(result);
|
|
108
|
-
pendingPermissionCall = null;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
// Solicitar el permiso
|
|
114
|
-
requestPermissionLauncher.launch(CAMERA_PERMISSION);
|
|
115
|
-
|
|
64
|
+
if (getPermissionState("camera") != PermissionState.GRANTED) {
|
|
65
|
+
requestPermissionForAlias("camera", call, "cameraPermissionCallback");
|
|
116
66
|
} else {
|
|
117
|
-
// Para versiones anteriores
|
|
118
67
|
JSObject ret = new JSObject();
|
|
119
68
|
ret.put("granted", true);
|
|
120
69
|
ret.put("status", "granted");
|
|
121
|
-
ret.put("details", "
|
|
70
|
+
ret.put("details", "Already granted");
|
|
122
71
|
call.resolve(ret);
|
|
123
72
|
}
|
|
124
73
|
}
|
|
125
74
|
|
|
75
|
+
@PermissionCallback
|
|
76
|
+
private void cameraPermissionCallback(PluginCall call) {
|
|
77
|
+
JSObject ret = new JSObject();
|
|
78
|
+
boolean granted = getPermissionState("camera") == PermissionState.GRANTED;
|
|
79
|
+
|
|
80
|
+
ret.put("granted", granted);
|
|
81
|
+
ret.put("status", granted ? "granted" : "denied");
|
|
82
|
+
ret.put("details", "Permission request completed");
|
|
83
|
+
|
|
84
|
+
call.resolve(ret);
|
|
85
|
+
}
|
|
86
|
+
|
|
126
87
|
@PluginMethod
|
|
127
88
|
public void checkAndRequestPermission(PluginCall call) {
|
|
128
|
-
if (
|
|
129
|
-
int permissionStatus = ContextCompat.checkSelfPermission(
|
|
130
|
-
getContext(),
|
|
131
|
-
CAMERA_PERMISSION
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
if (permissionStatus == PackageManager.PERMISSION_GRANTED) {
|
|
135
|
-
JSObject ret = new JSObject();
|
|
136
|
-
ret.put("granted", true);
|
|
137
|
-
ret.put("status", "granted");
|
|
138
|
-
ret.put("details", "Already granted");
|
|
139
|
-
call.resolve(ret);
|
|
140
|
-
} else {
|
|
141
|
-
requestPermission(call);
|
|
142
|
-
}
|
|
143
|
-
} else {
|
|
89
|
+
if (getPermissionState("camera") == PermissionState.GRANTED) {
|
|
144
90
|
JSObject ret = new JSObject();
|
|
145
91
|
ret.put("granted", true);
|
|
146
92
|
ret.put("status", "granted");
|
|
147
|
-
ret.put("details", "
|
|
93
|
+
ret.put("details", "Already granted");
|
|
148
94
|
call.resolve(ret);
|
|
95
|
+
} else {
|
|
96
|
+
requestPermission(call);
|
|
149
97
|
}
|
|
150
98
|
}
|
|
151
|
-
|
|
99
|
+
|
|
100
|
+
@PluginMethod
|
|
101
|
+
public void getCameraCapabilities(PluginCall call) {
|
|
102
|
+
JSObject ret = new JSObject();
|
|
103
|
+
|
|
104
|
+
boolean hasCamera = getContext()
|
|
105
|
+
.getPackageManager()
|
|
106
|
+
.hasSystemFeature("android.hardware.camera.any");
|
|
107
|
+
|
|
108
|
+
ret.put("hasCamera", hasCamera);
|
|
109
|
+
ret.put("isSecureContext", true);
|
|
110
|
+
ret.put("userAgent", "Android");
|
|
111
|
+
|
|
112
|
+
call.resolve(ret);
|
|
113
|
+
}
|
|
114
|
+
}
|
package/dist/docs.json
CHANGED
|
@@ -5,22 +5,6 @@
|
|
|
5
5
|
"docs": "",
|
|
6
6
|
"tags": [],
|
|
7
7
|
"methods": [
|
|
8
|
-
{
|
|
9
|
-
"name": "echo",
|
|
10
|
-
"signature": "(options: { value: string; }) => Promise<{ value: string; }>",
|
|
11
|
-
"parameters": [
|
|
12
|
-
{
|
|
13
|
-
"name": "options",
|
|
14
|
-
"docs": "",
|
|
15
|
-
"type": "{ value: string; }"
|
|
16
|
-
}
|
|
17
|
-
],
|
|
18
|
-
"returns": "Promise<{ value: string; }>",
|
|
19
|
-
"tags": [],
|
|
20
|
-
"docs": "",
|
|
21
|
-
"complexTypes": [],
|
|
22
|
-
"slug": "echo"
|
|
23
|
-
},
|
|
24
8
|
{
|
|
25
9
|
"name": "echo",
|
|
26
10
|
"signature": "(options: { value: string; }) => Promise<{ value: string; }>",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CameraModulePlugin {\n
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CameraModulePlugin {\n\n echo(options: { value: string }): Promise<{ value: string }>;\n\n checkPermission(): Promise<PermissionStatus>;\n\n requestPermission(): Promise<PermissionStatus>;\n\n checkAndRequestPermission(): Promise<PermissionStatus>;\n\n getCameraCapabilities(): Promise<CameraCapabilities>;\n}\n\nexport interface PermissionStatus {\n granted: boolean;\n status: 'granted' | 'denied' | 'prompt' | 'prompt-with-rationale' | 'limited';\n details?: string;\n}\n\n\nexport interface CameraCapabilities {\n hasCamera: boolean;\n isSecureContext: boolean;\n userAgent: string;\n}"]}
|