Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
fix(mqtt): send ? when gps is not available
Browse files Browse the repository at this point in the history
Signed-off-by: Rafa Hernandez <rhernandez@teclib.com>
  • Loading branch information
rafaelje authored and Ivan Del Pino committed Dec 5, 2018
1 parent bacaf17 commit 316ea15
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/src/main/assets/about.properties
@@ -1,6 +1,6 @@
about.version=2.0.0-rc.5
about.build=2969
about.date=Tue Nov 27 10:21:04 2018
about.date=Tue Nov 27 11:12:03 2018
about.commit=
about.commitFull=
about.github=https://github.com/flyve-mdm/flyve-mdm-android-agent
Expand Up @@ -525,7 +525,8 @@ public void sendOnlineStatus(Boolean status) {
*/
public void sendGPS() {

new FastLocationProvider().getLocation(context, new FastLocationProvider.LocationResult() {
FastLocationProvider fastLocationProvider = new FastLocationProvider();
Boolean isAvailable = fastLocationProvider.getLocation(context, new FastLocationProvider.LocationResult() {
@Override
public void gotLocation(Location location) {
String topic = mTopic + "/Status/Geolocation";
Expand Down Expand Up @@ -572,6 +573,20 @@ public void gotLocation(Location location) {
}
}
});

if(!isAvailable) {
String topic = mTopic + "/Status/Geolocation";
try {
byte[] encodedPayload;
String payload = "?";
encodedPayload = payload.getBytes(UTF_8);
MqttMessage message = new MqttMessage(encodedPayload);
client.publish(topic, message);
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", sendGPS", "Fail sending the ? payload");
}

}
}

/**
Expand Down
Expand Up @@ -81,7 +81,7 @@ public boolean getLocation(Context context, LocationResult result) {
}

timer = new Timer();
timer.schedule(new GetLastLocation(), 10000);
timer.schedule(new GetLastLocation(), 3000);

return true;
}
Expand Down Expand Up @@ -144,6 +144,7 @@ public void run() {
}
} catch (SecurityException ex) {
FlyveLog.e(this.getClass().getName() + ", GetLastLocation", ex.getMessage());
locationResult.gotLocation(null);
}

//if there are both values use the latest one
Expand Down

0 comments on commit 316ea15

Please sign in to comment.