Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. public class GeofenceTransitionsIntentService extends IntentService {
  2. ...
  3. protected void onHandleIntent(Intent intent) {
  4. GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
  5. if (geofencingEvent.hasError()) {
  6. String errorMessage = GeofenceErrorMessages.getErrorString(this,
  7. geofencingEvent.getErrorCode());
  8. Log.e(TAG, errorMessage);
  9. return;
  10. }
  11.  
  12. // Tipo di transition (ENTER / EXIT)
  13. int geofenceTransition = geofencingEvent.getGeofenceTransition();
  14.  
  15. // Verifica che la transizione sia quella richiesta
  16. if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
  17. geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
  18.  
  19. // Prelevo l'array delle geofence ricevute dall'IntentService
  20. List triggeringGeofences = geofencingEvent.getTriggeringGeofences();
  21.  
  22. // Get the transition details as a String.
  23. String geofenceTransitionDetails = getGeofenceTransitionDetails(
  24. this,
  25. geofenceTransition,
  26. triggeringGeofences
  27. );
  28.  
  29. //TODO: logica legata alla richiesta, es. mostro notifica
  30. Log.i(TAG, geofenceTransitionDetails);
  31. } else {
  32. // Log the error.
  33. Log.e(TAG, getString(R.string.geofence_transition_invalid_type,
  34. geofenceTransition));
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement