use of com.google.android.gms.location.Geofence in project Android-ReactiveLocation by mcharmas.
the class GeofenceActivity method createGeofencingRequest.
private GeofencingRequest createGeofencingRequest() {
try {
double longitude = Double.parseDouble(longitudeInput.getText().toString());
double latitude = Double.parseDouble(latitudeInput.getText().toString());
float radius = Float.parseFloat(radiusInput.getText().toString());
Geofence geofence = new Geofence.Builder().setRequestId("GEOFENCE").setCircularRegion(latitude, longitude, radius).setExpirationDuration(Geofence.NEVER_EXPIRE).setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT).build();
return new GeofencingRequest.Builder().addGeofence(geofence).build();
} catch (NumberFormatException ex) {
toast("Error parsing input.");
return null;
}
}
use of com.google.android.gms.location.Geofence in project Remindy by abicelis.
the class GeofenceNotificationIntentService method onHandleIntent.
@Override
protected void onHandleIntent(@Nullable Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage = GeofenceErrorMessages.getErrorString(this, geofencingEvent.getErrorCode());
Log.e(TAG, errorMessage);
return;
}
// Get the transition type.
int geofenceTransition = geofencingEvent.getGeofenceTransition();
// Log the transition type
handleLogTransition(geofenceTransition);
// Test that the reported transition was of interest.
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || //|| geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER //Skipping this transition because of alert spam issues
geofenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) {
for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
List<Task> tasks = new ArrayList<>();
try {
tasks = new RemindyDAO(this).getLocationBasedTasksAssociatedWithPlace(Integer.valueOf(geofence.getRequestId()), geofenceTransition);
} catch (CouldNotGetDataException e) {
/* Do nothing */
}
if (tasks.size() > 0) {
String notificationTitle = getGeofenceNotificationTitle(geofenceTransition, geofence);
String notificationText = getGeofenceNotificationText(tasks);
// Send notification and log the transition details.
NotificationUtil.displayLocationBasedNotification(this, Integer.valueOf(geofence.getRequestId()), notificationTitle, notificationText, tasks);
Log.i(TAG, notificationTitle + " " + notificationText);
}
}
}
}
Aggregations