Search in sources :

Example 1 with Geofence

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;
    }
}
Also used : Geofence(com.google.android.gms.location.Geofence)

Example 2 with Geofence

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);
            }
        }
    }
}
Also used : Task(ve.com.abicelis.remindy.model.Task) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) ArrayList(java.util.ArrayList) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) GeofencingEvent(com.google.android.gms.location.GeofencingEvent) Geofence(com.google.android.gms.location.Geofence)

Aggregations

Geofence (com.google.android.gms.location.Geofence)2 GeofencingEvent (com.google.android.gms.location.GeofencingEvent)1 ArrayList (java.util.ArrayList)1 RemindyDAO (ve.com.abicelis.remindy.database.RemindyDAO)1 CouldNotGetDataException (ve.com.abicelis.remindy.exception.CouldNotGetDataException)1 Task (ve.com.abicelis.remindy.model.Task)1