use of com.google.android.gms.location.GeofencingEvent in project Android-ReactiveLocation by mcharmas.
the class GeofenceBroadcastReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
GeofencingEvent event = GeofencingEvent.fromIntent(intent);
String transition = mapTransition(event.getGeofenceTransition());
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_launcher).setContentTitle("Geofence action").setContentText(transition).setTicker("Geofence action").build();
nm.notify(0, notification);
}
use of com.google.android.gms.location.GeofencingEvent in project mobile-messaging-sdk-android by infobip.
the class GeoTransitionHelper method resolveTransitionFromIntent.
/**
* Resolves transition information from geofencing intent
*
* @param intent geofencing intent
* @return transition information
* @throws RuntimeException if information cannot be resolved
*/
static GeoTransition resolveTransitionFromIntent(Intent intent) throws RuntimeException {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent == null) {
throw new RuntimeException("Geofencing event is null, cannot process");
}
if (geofencingEvent.hasError()) {
if (geofencingEvent.getErrorCode() == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE) {
throw new GeofenceNotAvailableException();
}
throw new RuntimeException("ERROR: " + GeofenceStatusCodes.getStatusCodeString(geofencingEvent.getErrorCode()));
}
GeoEventType event = supportedTransitionEvents.get(geofencingEvent.getGeofenceTransition());
if (event == null) {
throw new RuntimeException("Transition is not supported: " + geofencingEvent.getGeofenceTransition());
}
Set<String> triggeringRequestIds = new ArraySet<>();
for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
triggeringRequestIds.add(geofence.getRequestId());
}
Location location = geofencingEvent.getTriggeringLocation();
return new GeoTransition(event, triggeringRequestIds, new GeoLatLng(location.getLatitude(), location.getLongitude()));
}
use of com.google.android.gms.location.GeofencingEvent 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) {
Log.e("TAG", "Could not get data, geofence notification service.", e);
}
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);
}
}
}
}
use of com.google.android.gms.location.GeofencingEvent in project android-play-location by googlesamples.
the class GeofenceTransitionsJobIntentService method onHandleWork.
/**
* Handles incoming intents.
* @param intent sent by Location Services. This Intent is provided to Location
* Services (inside a PendingIntent) when addGeofences() is called.
*/
@Override
protected void onHandleWork(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();
// Test that the reported transition was of interest.
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
// Get the geofences that were triggered. A single event can trigger multiple geofences.
List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
// Get the transition details as a String.
String geofenceTransitionDetails = getGeofenceTransitionDetails(geofenceTransition, triggeringGeofences);
// Send notification and log the transition details.
sendNotification(geofenceTransitionDetails);
Log.i(TAG, geofenceTransitionDetails);
} else {
// Log the error.
Log.e(TAG, getString(R.string.geofence_transition_invalid_type, geofenceTransition));
}
}
use of com.google.android.gms.location.GeofencingEvent in project CodenameOne by codenameone.
the class GeofenceHandler method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
String className = intent.getStringExtra("geofenceClass");
String id = intent.getStringExtra("geofenceID");
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
for (com.google.android.gms.location.Geofence gf : geofencingEvent.getTriggeringGeofences()) {
try {
id = gf.getRequestId();
GeofenceListener l = (GeofenceListener) Class.forName(className).newInstance();
if (geofencingEvent.getGeofenceTransition() == com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_ENTER) {
l.onEntered(id);
} else if (geofencingEvent.getGeofenceTransition() == com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_EXIT) {
l.onExit(id);
}
} catch (Exception e) {
Log.e("Codename One", "geofence error", e);
}
}
}
Aggregations