Skip to content

Commit 989fa1e

Browse files
authored
fix(location): fix location issue. (#154)
* fix(location): fix location issue.
1 parent 26f2bc7 commit 989fa1e

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

AndroidSDKCore/src/main/java/com/leanplum/internal/ActionManager.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class ActionManager {
5454
private static final String LEANPLUM_LOCAL_PUSH_HELPER =
5555
"com.leanplum.internal.LeanplumLocalPushHelper";
5656
private static final String PREFERENCES_NAME = "__leanplum_messaging__";
57+
private static boolean loggedLocationManagerFailure = false;
5758

5859
public static class MessageMatchResult {
5960
public boolean matchedTrigger;
@@ -68,29 +69,21 @@ public static synchronized ActionManager getInstance() {
6869
return instance;
6970
}
7071

71-
private static boolean loggedLocationManagerFailure = false;
72-
7372
public static LocationManager getLocationManager() {
7473
if (Util.hasPlayServices()) {
7574
try {
76-
Class<?> googleApiClientClass =
77-
Class.forName("com.google.android.gms.common.api.GoogleApiClient");
78-
if (googleApiClientClass != null
79-
&& Modifier.isAbstract(googleApiClientClass.getModifiers())
80-
&& Modifier.isAbstract(
81-
googleApiClientClass.getMethod("isConnected").getModifiers())
82-
&& Class.forName("com.google.android.gms.location.LocationServices") != null) {
83-
// Reflection here prevents linker errors
84-
// in Google Play Services is not used in the client app.
85-
return (LocationManager) Class
86-
.forName("com.leanplum.LocationManagerImplementation")
87-
.getMethod("instance").invoke(null);
88-
}
75+
// Reflection here prevents linker errors
76+
// if Google Play Services is not used in the client app.
77+
return (LocationManager) Class
78+
.forName("com.leanplum.LocationManagerImplementation")
79+
.getMethod("instance").invoke(null);
8980
} catch (Throwable t) {
9081
if (!loggedLocationManagerFailure) {
91-
Log.e("Geofencing support requires Google Play Services v8.1 and higher.\n" +
82+
Log.w("Geofencing support requires leanplum-location module and Google Play " +
83+
"Services v8.1 and higher.\n" +
9284
"Add this to your build.gradle file:\n" +
93-
"compile ('com.google.android.gms:play-services-location:8.3.0+')");
85+
"implementation 'com.google.android.gms:play-services-location:8.3.0+'\n" +
86+
"implementation 'com.leanplum:leanplum-location:+'");
9487
loggedLocationManagerFailure = true;
9588
}
9689
}
@@ -136,7 +129,6 @@ public boolean onResponse(ActionContext actionContext) {
136129
.getDeclaredMethod("scheduleLocalPush", ActionContext.class, String.class,
137130
long.class).invoke(new Object(), actionContext, messageId, eta);
138131
} catch (Throwable throwable) {
139-
Log.e("scheduleLocalPush problem",throwable);
140132
return false;
141133
}
142134
} catch (Throwable t) {

AndroidSDKLocation/src/main/java/com/leanplum/LocationManagerImplementation.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,16 @@ class LocationManagerImplementation implements
101101
private static LocationManagerImplementation instance;
102102

103103
public static synchronized LocationManager instance() {
104-
if (instance == null) {
105-
instance = new LocationManagerImplementation();
104+
try {
105+
if (LocationServices.API != null) {
106+
if (instance == null) {
107+
instance = new LocationManagerImplementation();
108+
}
109+
return instance;
110+
}
111+
} catch (Throwable ignored) {
106112
}
107-
return instance;
113+
return null;
108114
}
109115

110116
private LocationManagerImplementation() {
@@ -287,11 +293,8 @@ private void updateTrackedGeofences() {
287293
}
288294
trackedGeofenceIds = new ArrayList<>();
289295
if (toBeTrackedGeofences != null && toBeTrackedGeofences.size() > 0) {
290-
GeofencingRequest request = new GeofencingRequest.Builder()
291-
.addGeofences(toBeTrackedGeofences)
292-
.build();
293296
LocationServices.GeofencingApi.addGeofences(googleApiClient,
294-
request, getTransitionPendingIntent());
297+
toBeTrackedGeofences, getTransitionPendingIntent());
295298
for (Geofence geofence : toBeTrackedGeofences) {
296299
if (geofence != null && geofence.getRequestId() != null) {
297300
trackedGeofenceIds.add(geofence.getRequestId());

0 commit comments

Comments
 (0)