diff --git a/src/android/SimpleCameraPreview.java b/src/android/SimpleCameraPreview.java index 42a4eb6..a7503b9 100644 --- a/src/android/SimpleCameraPreview.java +++ b/src/android/SimpleCameraPreview.java @@ -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) { @@ -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); }