Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GeofenceTransitionsIntentService extends IntentService {
- ...
- protected void onHandleIntent(Intent intent) {
- GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
- if (geofencingEvent.hasError()) {
- String errorMessage = GeofenceErrorMessages.getErrorString(this,
- geofencingEvent.getErrorCode());
- Log.e(TAG, errorMessage);
- return;
- }
- // Tipo di transition (ENTER / EXIT)
- int geofenceTransition = geofencingEvent.getGeofenceTransition();
- // Verifica che la transizione sia quella richiesta
- if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
- geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
- // Prelevo l'array delle geofence ricevute dall'IntentService
- List triggeringGeofences = geofencingEvent.getTriggeringGeofences();
- // Get the transition details as a String.
- String geofenceTransitionDetails = getGeofenceTransitionDetails(
- this,
- geofenceTransition,
- triggeringGeofences
- );
- //TODO: logica legata alla richiesta, es. mostro notifica
- Log.i(TAG, geofenceTransitionDetails);
- } else {
- // Log the error.
- Log.e(TAG, getString(R.string.geofence_transition_invalid_type,
- geofenceTransition));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement