Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addObserver issue fix: using context rather than activity in LocationServices #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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