@@ -70,20 +70,14 @@ private void checkLocationService(Boolean activityResult) {
7070 LocationManager locationManager = (LocationManager ) currentActivity .getSystemService (Context .LOCATION_SERVICE );
7171 WritableMap result = Arguments .createMap ();
7272
73- Boolean isEnabled = locationManager .isProviderEnabled (LocationManager .GPS_PROVIDER );
74-
75- if (map .hasKey ("enableHighAccuracy" ) && map .getBoolean ("enableHighAccuracy" )) {
76- // High accuracy needed. Require NETWORK_PROVIDER.
77- isEnabled = isEnabled && locationManager .isProviderEnabled (LocationManager .NETWORK_PROVIDER );
78- } else {
79- // Either highAccuracy is not a must which means any location will suffice
80- // or it is not specified which means again that any location will do.
81- isEnabled = isEnabled || locationManager .isProviderEnabled (LocationManager .NETWORK_PROVIDER );
82- }
73+ Boolean isEnabled = this .isEnabled (locationManager );
8374
8475 if (!isEnabled ) {
8576 if (activityResult || map .hasKey ("openLocationServices" ) && !map .getBoolean ("openLocationServices" )) {
8677 promiseCallback .reject (new Throwable ("disabled" ));
78+ if (map .hasKey ("providerListener" ) && map .getBoolean ("providerListener" )) {
79+ startListener ();
80+ }
8781 } else if (!map .hasKey ("showDialog" ) || map .getBoolean ("showDialog" )) {
8882 displayPromptForEnablingGPS (currentActivity , map , promiseCallback );
8983 } else {
@@ -187,12 +181,28 @@ private void startListener() {
187181 }
188182 }
189183
184+ private Boolean isEnabled (LocationManager locationManager ) {
185+ Boolean enabled = locationManager .isProviderEnabled (LocationManager .GPS_PROVIDER );
186+ if (map != null ) {
187+ if (map .hasKey ("enableHighAccuracy" ) && map .getBoolean ("enableHighAccuracy" )) {
188+ // High accuracy needed. Require NETWORK_PROVIDER.
189+ enabled = enabled && locationManager .isProviderEnabled (LocationManager .NETWORK_PROVIDER );
190+ } else {
191+ // Either highAccuracy is not a must which means any location will suffice
192+ // or it is not specified which means again that any location will do.
193+ enabled = enabled || locationManager .isProviderEnabled (LocationManager .NETWORK_PROVIDER );
194+ }
195+ }
196+
197+ return enabled ;
198+ }
199+
190200 private void sendEvent () {
191201 if (isReceive ) {
192202 LocationManager locationManager = (LocationManager ) currentActivity .getSystemService (Context .LOCATION_SERVICE );
193203 WritableMap params = Arguments .createMap ();
194204 if (locationManager != null ) {
195- boolean enabled = locationManager . isProviderEnabled ( LocationManager . GPS_PROVIDER );
205+ boolean enabled = this . isEnabled ( locationManager );
196206
197207 params .putString ("status" , (enabled ? "enabled" : "disabled" ));
198208 params .putBoolean ("enabled" , enabled );
@@ -222,4 +232,4 @@ public void onReceive(Context context, Intent intent) {
222232 }
223233 }
224234 }
225- }
235+ }
0 commit comments