Skip to content

Commit 3a1f48a

Browse files
committed
Use the enableHighAccuracy parameter in the listener as well.
1 parent 87eed85 commit 3a1f48a

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

android/src/main/java/com/showlocationservicesdialogbox/LocationServicesDialogBoxModule.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,7 @@ 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")) {
@@ -187,12 +178,28 @@ private void startListener() {
187178
}
188179
}
189180

181+
private Boolean isEnabled(LocationManager locationManager) {
182+
Boolean enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
183+
if (map != null) {
184+
if (map.hasKey("enableHighAccuracy") && map.getBoolean("enableHighAccuracy")) {
185+
// High accuracy needed. Require NETWORK_PROVIDER.
186+
enabled = enabled && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
187+
} else {
188+
// Either highAccuracy is not a must which means any location will suffice
189+
// or it is not specified which means again that any location will do.
190+
enabled = enabled || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
191+
}
192+
}
193+
194+
return enabled;
195+
}
196+
190197
private void sendEvent() {
191198
if (isReceive) {
192199
LocationManager locationManager = (LocationManager) currentActivity.getSystemService(Context.LOCATION_SERVICE);
193200
WritableMap params = Arguments.createMap();
194201
if (locationManager != null) {
195-
boolean enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
202+
boolean enabled = this.isEnabled(locationManager);
196203

197204
params.putString("status", (enabled ? "enabled" : "disabled"));
198205
params.putBoolean("enabled", enabled);
@@ -222,4 +229,4 @@ public void onReceive(Context context, Intent intent) {
222229
}
223230
}
224231
}
225-
}
232+
}

0 commit comments

Comments
 (0)