apache / cordova-plugin-camera

Apache Cordova Plugin camera
https://cordova.apache.org/
Apache License 2.0
960 stars 1.52k forks source link

Implement stop() to close CAMERA or PHOTOLIBRARY #873

Open NityaSantosh26 opened 5 months ago

NityaSantosh26 commented 5 months ago

Platforms affected

Android and iOS

Motivation and Context

I have an usecase where user opens camera and if there's an high priority push notification is received, when user clicks, it doesn't close the camera, User has to manually close the camera. Now using the navigator.camera.stop(). I can achieve this behavior. And there are other instances which needs closing of camera or photo library from the code.

Description

Added a new method stop() which handles the closing of CAMERA or PHOTOLIBRARY for both Android and iOS.

Testing

I have verified the usecase I have mentioned above, when a push notification is clicked that closes the camera and takes to the destination page in the module by calling the stop() method.

Checklist

breautek commented 5 months ago

This PR doesn't compile on android:

> Task :app:compileDebugJavaWithJavac FAILED
/private/var/folders/3s/vfzpb5r51gs6y328rmlgzm7c0000gn/T/tmp-6830-P1sEoh8XyXcJ/platforms/android/app/src/main/java/org/apache/cordova/camera/CameraLauncher.java:361: error: cannot find symbol
            this.cordova.getActivity().finishActivity((CAMERA + 1) * 16 + returnType + 1);
                                                                          ^
  symbol:   variable returnType
  location: class CameraLauncher
/private/var/folders/3s/vfzpb5r51gs6y328rmlgzm7c0000gn/T/tmp-6830-P1sEoh8XyXcJ/platforms/android/app/src/main/java/org/apache/cordova/camera/CameraLauncher.java:[362](https://github.com/apache/cordova-plugin-camera/actions/runs/7110255438/job/19459961261?pr=873#step:9:366): error: cannot find symbol
            this.cordova.getActivity().finishActivity((PHOTOLIBRARY + 1) * 16 + returnType + 1);
                                                                                ^
  symbol:   variable returnType
  location: class CameraLauncher
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors

Additionally there are lint issues present in this PR:

/home/runner/work/cordova-plugin-camera/cordova-plugin-camera/www/Camera.js
Error:   158:1  error  Unexpected tab character                          no-tabs
Error:   158:1  error  Expected indentation of 4 spaces but found 1 tab  indent
NityaSantosh26 commented 5 months ago

@breautek, My bad. I had an incomplete commit. Let me update my commit. Can you review the PR. It's complete now.