Skip to content

Commit

Permalink
Merge pull request #84 from spoonconsulting/remove-location-permission
Browse files Browse the repository at this point in the history
Remove location permission from REQUIRED_PERMISSIONS
  • Loading branch information
HashirRajah authored Jul 29, 2024
2 parents 7750113 + 7c265ea commit 86d7303
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 34 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [2.0.24](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/compare/v2.0.23...v2.0.24) (2024-07-29)
* **Android:** Remove ACCESS_FINE_LOCATION as a required permission

## [2.0.23](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/compare/v2.0.22...v2.0.23) (2024-07-17)
* **Android:** Use parameter lens with values wide or default
* **iOS:** Use parameter lens with values wide or default
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spoonconsulting/cordova-plugin-simple-camera-preview",
"version": "2.0.23",
"version": "2.0.24",
"description": "Cordova plugin that allows camera interaction from HTML code for showing camera preview below or on top of the HTML.",
"keywords": [
"cordova",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<plugin id="@spoonconsulting/cordova-plugin-simple-camera-preview" version="2.0.23" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="@spoonconsulting/cordova-plugin-simple-camera-preview" version="2.0.24" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">

<name>cordova-plugin-simple-camera-preview</name>
<description>Cordova plugin that allows camera interaction from HTML code. Show camera preview popup on top of the HTML.</description>
Expand Down
52 changes: 22 additions & 30 deletions src/android/SimpleCameraPreview.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class SimpleCameraPreview extends CordovaPlugin {
private static final int DIRECTION_FRONT = 0;
private static final int DIRECTION_BACK = 1;
private static final int REQUEST_CODE_PERMISSIONS = 4582679;
private static final String[] REQUIRED_PERMISSIONS = {Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION};
private static final String REQUIRED_PERMISSION = Manifest.permission.CAMERA;

public SimpleCameraPreview() {
super();
Expand Down Expand Up @@ -123,7 +123,7 @@ private boolean enable(JSONObject options, CallbackContext callbackContext) {
webView.getView().setBackgroundColor(0x00000000);
// Request focus on webView as page needs to be clicked/tapped to get focus on page events
webView.getView().requestFocus();
if (!this.hasAllPermissions()) {
if (!PermissionHelper.hasPermission(this, REQUIRED_PERMISSION)) {
this.enableCallbackContext = callbackContext;
this.options = options;
this.requestPermissions();
Expand Down Expand Up @@ -213,7 +213,25 @@ public void run() {
);
cordova.getActivity().runOnUiThread(addViewTask);
addViewTask.get();
fetchLocation();
return true;
} catch (Exception e) {
e.printStackTrace();
callbackContext.error(e.getMessage());
return false;
}
}

private int getIntegerFromOptions(JSONObject options, String key) {
try {
return options.getInt(key);
} catch (JSONException error) {
return 0;
}
}

public void fetchLocation() {
if (ContextCompat.checkSelfPermission(cordova.getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mLocationCallback = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Expand All @@ -237,25 +255,6 @@ public void onProviderDisabled(String provider) {

}
};
fetchLocation();
return true;
} catch (Exception e) {
e.printStackTrace();
callbackContext.error(e.getMessage());
return false;
}
}

private int getIntegerFromOptions(JSONObject options, String key) {
try {
return options.getInt(key);
} catch (JSONException error) {
return 0;
}
}

public void fetchLocation() {
if (ContextCompat.checkSelfPermission(cordova.getActivity(), REQUIRED_PERMISSIONS[1]) == PackageManager.PERMISSION_GRANTED) {
if (locationManager == null) {
locationManager = (LocationManager) cordova.getActivity().getSystemService(Context.LOCATION_SERVICE);
}
Expand Down Expand Up @@ -365,17 +364,10 @@ private boolean switchCameraTo(String device, CallbackContext callbackContext) {
return true;
}

public boolean hasAllPermissions() {
for(String p : REQUIRED_PERMISSIONS) {
if(!PermissionHelper.hasPermission(this, p)) {
return false;
}
}
return true;
}

public void requestPermissions() {
PermissionHelper.requestPermissions(this, REQUEST_CODE_PERMISSIONS, REQUIRED_PERMISSIONS);
String[] permissions = {REQUIRED_PERMISSION};
PermissionHelper.requestPermissions(this, REQUEST_CODE_PERMISSIONS, permissions);
}

public boolean permissionsGranted(int[] grantResults) {
Expand Down

0 comments on commit 86d7303

Please sign in to comment.