capacitor-camera-module 0.0.2 → 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&lt;{ value: string; }&gt;</code>
55
-
56
- --------------------
57
-
58
-
59
43
  ### checkPermission()
60
44
 
61
45
  ```typescript
@@ -55,4 +55,7 @@ dependencies {
55
55
  testImplementation "junit:junit:$junitVersion"
56
56
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
57
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
+
59
+ implementation 'androidx.activity:activity:1.7.0'
60
+ implementation 'androidx.fragment:fragment:1.5.7'
58
61
  }
@@ -1,2 +1,12 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ package="com.eddieagvictoria.cameramodule">
3
+
4
+ <!-- Permiso de cámara -->
5
+ <uses-permission android:name="android.permission.CAMERA" />
6
+
7
+ <!-- Características opcionales -->
8
+ <uses-feature android:name="android.hardware.camera" android:required="false" />
9
+ <uses-feature android:name="android.hardware.camera.front" android:required="false" />
10
+ <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
11
+
2
12
  </manifest>
@@ -1,22 +1,114 @@
1
1
  package com.eddieagvictoria.cameramodule;
2
2
 
3
+ import android.Manifest;
4
+ import android.os.Build;
5
+ import android.content.pm.PackageManager;
6
+
7
+ import androidx.core.content.ContextCompat;
8
+
3
9
  import com.getcapacitor.JSObject;
4
10
  import com.getcapacitor.Plugin;
5
11
  import com.getcapacitor.PluginCall;
6
12
  import com.getcapacitor.PluginMethod;
13
+ import com.getcapacitor.PermissionState;
7
14
  import com.getcapacitor.annotation.CapacitorPlugin;
15
+ import com.getcapacitor.annotation.Permission;
16
+ import com.getcapacitor.annotation.PermissionCallback;
8
17
 
9
- @CapacitorPlugin(name = "CameraModule")
18
+ @CapacitorPlugin(
19
+ name = "CameraModule",
20
+ permissions = {
21
+ @Permission(
22
+ alias = "camera",
23
+ strings = { Manifest.permission.CAMERA }
24
+ )
25
+ }
26
+ )
10
27
  public class CameraModulePlugin extends Plugin {
11
28
 
12
- private CameraModule implementation = new CameraModule();
13
-
14
29
  @PluginMethod
15
30
  public void echo(PluginCall call) {
16
- String value = call.getString("value");
31
+ String value = call.getString("value", "");
32
+ JSObject ret = new JSObject();
33
+ ret.put("value", value);
34
+ call.resolve(ret);
35
+ }
36
+
37
+ @PluginMethod
38
+ public void checkPermission(PluginCall call) {
39
+ JSObject ret = new JSObject();
40
+
41
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
42
+ ret.put("granted", true);
43
+ ret.put("status", "granted");
44
+ ret.put("details", "Pre-Marshmallow, granted at install");
45
+ call.resolve(ret);
46
+ return;
47
+ }
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
+
59
+ call.resolve(ret);
60
+ }
17
61
 
62
+ @PluginMethod
63
+ public void requestPermission(PluginCall call) {
64
+ if (getPermissionState("camera") != PermissionState.GRANTED) {
65
+ requestPermissionForAlias("camera", call, "cameraPermissionCallback");
66
+ } else {
67
+ JSObject ret = new JSObject();
68
+ ret.put("granted", true);
69
+ ret.put("status", "granted");
70
+ ret.put("details", "Already granted");
71
+ call.resolve(ret);
72
+ }
73
+ }
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
+
87
+ @PluginMethod
88
+ public void checkAndRequestPermission(PluginCall call) {
89
+ if (getPermissionState("camera") == PermissionState.GRANTED) {
90
+ JSObject ret = new JSObject();
91
+ ret.put("granted", true);
92
+ ret.put("status", "granted");
93
+ ret.put("details", "Already granted");
94
+ call.resolve(ret);
95
+ } else {
96
+ requestPermission(call);
97
+ }
98
+ }
99
+
100
+ @PluginMethod
101
+ public void getCameraCapabilities(PluginCall call) {
18
102
  JSObject ret = new JSObject();
19
- ret.put("value", implementation.echo(value));
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
+
20
112
  call.resolve(ret);
21
113
  }
22
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,9 +1,4 @@
1
1
  export interface CameraModulePlugin {
2
- echo(options: {
3
- value: string;
4
- }): Promise<{
5
- value: string;
6
- }>;
7
2
  echo(options: {
8
3
  value: string;
9
4
  }): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CameraModulePlugin {\n echo(options: { value: string }): Promise<{ value: string }>;\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}"]}
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}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-camera-module",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Plugin to request permissiones view camera take phots",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,11 +0,0 @@
1
- package com.eddieagvictoria.cameramodule;
2
-
3
- import com.getcapacitor.Logger;
4
-
5
- public class CameraModule {
6
-
7
- public String echo(String value) {
8
- Logger.info("Echo", value);
9
- return value;
10
- }
11
- }