Skip to content

Commit

Permalink
Correct checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hashir Rajah authored and Hashir Rajah committed Jul 15, 2024
1 parent f01ea2c commit a8eac3b
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/android/SimpleCameraPreview.java
Original file line number Diff line number Diff line change
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

0 comments on commit a8eac3b

Please sign in to comment.