From b895c4dde6744a2c3cef178d8ad9ea0138c38456 Mon Sep 17 00:00:00 2001 From: timonibus Date: Mon, 27 May 2019 08:45:32 +0200 Subject: [PATCH] Use context for location provider if activity is not available The current activity may be null when the location provider is created. Use the React application context in that case. --- .../location/RNPlayServicesLocationProvider.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/github/reactnativecommunity/location/RNPlayServicesLocationProvider.java b/android/src/main/java/com/github/reactnativecommunity/location/RNPlayServicesLocationProvider.java index cc88ff5..6dbdd3b 100644 --- a/android/src/main/java/com/github/reactnativecommunity/location/RNPlayServicesLocationProvider.java +++ b/android/src/main/java/com/github/reactnativecommunity/location/RNPlayServicesLocationProvider.java @@ -46,8 +46,13 @@ public class RNPlayServicesLocationProvider implements RNLocationProvider { public RNPlayServicesLocationProvider(Activity activity, ReactApplicationContext context) { this.context = context; - locationProvider = LocationServices.getFusedLocationProviderClient(activity); - locationSettingsClient = LocationServices.getSettingsClient(activity); + if (activity != null) { + locationProvider = LocationServices.getFusedLocationProviderClient(activity); + locationSettingsClient = LocationServices.getSettingsClient(activity); + } else { + locationProvider = LocationServices.getFusedLocationProviderClient(context); + locationSettingsClient = LocationServices.getSettingsClient(context); + } } // Public interface