Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/
public class RNAndroidLocationEnablerModule extends ReactContextBaseJavaModule implements ActivityEventListener, OnCompleteListener<LocationSettingsResponse> {

private final ReactApplicationContext context;
private static final String SELF_MODULE_NAME = "RNAndroidLocationEnabler";
private static final String LOCATION_INTERVAL_DURATION_PARAMS_KEY = "interval";
private static final String LOCATION_FAST_INTERVAL_DURATION_PARAMS_KEY = "fastInterval";
Expand All @@ -54,12 +55,13 @@ public class RNAndroidLocationEnablerModule extends ReactContextBaseJavaModule i

public RNAndroidLocationEnablerModule(ReactApplicationContext reactContext) {
super(reactContext);
this.context = reactContext;
reactContext.addActivityEventListener(this);
}

@ReactMethod
public void promptForEnableLocationIfNeeded(ReadableMap params, Promise promise) {
if (getCurrentActivity() == null || params == null || promise == null) return;
if (getCurrentActivity() == null || params == null || promise == null || this.context == null) return;

this.promise = promise;

Expand All @@ -70,7 +72,7 @@ public void promptForEnableLocationIfNeeded(ReadableMap params, Promise promise)
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest);
builder.setAlwaysShow(true);
Task<LocationSettingsResponse> task = LocationServices.getSettingsClient(getCurrentActivity()).checkLocationSettings(builder.build());
Task<LocationSettingsResponse> task = LocationServices.getSettingsClient(this.context).checkLocationSettings(builder.build());
task.addOnCompleteListener(this);
}

Expand Down