Java 类com.google.android.gms.location.GeofencingEvent 实例源码

项目:Leanplum-Android-SDK    文件:ReceiveTransitionsIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
  try {
    GeofencingEvent event = GeofencingEvent.fromIntent(intent);
    if (event.hasError()) {
      int errorCode = event.getErrorCode();
      Log.d("Location Client Error with code: " + errorCode);
    } else {
      int transitionType = event.getGeofenceTransition();
      List<Geofence> triggeredGeofences = event.getTriggeringGeofences();
      if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER ||
          transitionType == Geofence.GEOFENCE_TRANSITION_EXIT) {
        LocationManagerImplementation locationManager = (LocationManagerImplementation)
            ActionManager.getLocationManager();
        if (locationManager != null) {
          locationManager.updateStatusForGeofences(triggeredGeofences, transitionType);
        }
      }
    }
  } catch (Throwable t) {
    Util.handleException(t);
  }
}
项目:SjekkUT    文件:GeofenceIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    GeofencingEvent fenceEvent = GeofencingEvent.fromIntent(intent);
    if (fenceEvent.hasError()) {
        String errorMessage = GeofenceStatusCodes.getStatusCodeString(fenceEvent.getErrorCode());
        Timber.i(errorMessage);
        return;
    }
    Timber.i("We got a geofence intent");

    if (fenceEvent.getGeofenceTransition() != Geofence.GEOFENCE_TRANSITION_DWELL
            || fenceEvent.getTriggeringGeofences().isEmpty()) {
        return;
    }

    String placeId = fenceEvent.getTriggeringGeofences().get(0).getRequestId();
    Realm realm = Realm.getDefaultInstance();
    Place place = Place.findFirst(realm, placeId);
    String title = place != null ?
            getString(R.string.geofence_notification_place_title, place.getName()) :
            getString(R.string.geofence_notification_title);
    String content = getString(R.string.geofence_notification_content);
    String imageUrl = place != null ? place.getFirstImage(GEOFENCE_LARGE_ICON_SIZE) : null;
    realm.close();
    sendNotification(title, content, placeId, imageUrl);
}
项目:TaskApp    文件:GeofenceTransitionsIntentService.java   
protected void onHandleIntent(Intent intent) {
    super.onHandleIntent(intent);

    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        Timber.e("geofence error code %s", geofencingEvent.getErrorCode());
        return;
    }

    int transitionType = geofencingEvent.getGeofenceTransition();

    List<com.google.android.gms.location.Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
    Timber.i("Received geofence transition: %s, %s", transitionType, triggeringGeofences);
    if (transitionType == com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_ENTER) {
        for (com.google.android.gms.location.Geofence triggerGeofence : triggeringGeofences) {
            triggerNotification(triggerGeofence);
        }
    } else {
        Timber.w("invalid geofence transition type: %s", transitionType);
    }
}
项目:aken-ajalukku    文件:GeofenceTransitionsReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    GeofencingEvent event = GeofencingEvent.fromIntent(intent);
    if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER)
        Log.d("aken-ajalukku", "Entered geofence!");
    else
        Log.d("aken-ajalukku", "Exited geofence!");
    if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER) {
        List<Geofence> geofences = event.getTriggeringGeofences();
        ArrayList<PointOfInterest> pois = new ArrayList<>();
        for (Geofence gf : geofences) {
            pois.add(Data.instance.getPoiById(Integer.parseInt(gf.getRequestId())));
        }
        createNotification(context, pois);
    }
}
项目:Android-App-Template    文件:GeofencingGooglePlayServicesProvider.java   
@Override
protected void onHandleIntent(Intent intent) {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent != null && !geofencingEvent.hasError()) {
        int transition = geofencingEvent.getGeofenceTransition();

        // Broadcast an intent containing the geofencing info
        Intent geofenceIntent = new Intent(BROADCAST_INTENT_ACTION);
        geofenceIntent.putExtra(TRANSITION_EXTRA_ID, transition);
        geofenceIntent.putExtra(LOCATION_EXTRA_ID, geofencingEvent.getTriggeringLocation());
        ArrayList<String> geofencingIds = new ArrayList<>();
        for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
            geofencingIds.add(geofence.getRequestId());
        }
        geofenceIntent.putStringArrayListExtra(GEOFENCES_EXTRA_ID, geofencingIds);
        sendBroadcast(geofenceIntent);
    }
}
项目:Android-GMapStars    文件:GeofenceReceiveService.java   
@Override
protected void onHandleIntent(Intent intent) {
    GeofencingEvent event = GeofencingEvent.fromIntent(intent);
    if (event != null && !event.hasError()) {
        int transition = event.getGeofenceTransition();
        Geofence fence = event.getTriggeringGeofences().get(0);
        Bundle extras = intent.getExtras();

        String id = fence.getRequestId();
        Matcher m = Pattern.compile("^([^\\t]+)\\t([^\\t]+)$").matcher(id);
        if(m.find()){
            Uri uri = Uri.parse(m.group(1));
            String name = m.group(2);
            switch (transition) {
                case Geofence.GEOFENCE_TRANSITION_ENTER:
                    Log.i("TAG", uri.toString()+" "+name);
                    sendNotification(uri, name);
                    break;
                case Geofence.GEOFENCE_TRANSITION_EXIT:
                    break;
            }

        }
    }
}
项目:orchextra-android-sdk    文件:GeofenceIntentService.java   
public void processGeofenceIntentPending(Intent intent) {
    if (geofenceHandler != null &&
            controller != null &&
            orchextraLogger != null) {
        try {
            GeofencingEvent geofencingEvent = geofenceHandler.getGeofencingEvent(intent);

            List<String> geofenceIds = geofenceHandler.getTriggeringGeofenceIds(geofencingEvent);
            GeoPointEventType transition = geofenceHandler.getGeofenceTransition(geofencingEvent);
            orchextraLogger.log("Localizado: " + transition.getStringValue());
            if (geofenceIds != null && !geofenceIds.isEmpty()) {
                controller.processTriggers(geofenceIds, transition);
            }
        } catch (GeofenceEventException geofenceEventException) {
            orchextraLogger.log(geofenceEventException.getMessage(), OrchextraSDKLogLevel.ERROR);
        }
    }
}
项目:Locative-Android    文件:ReceiveTransitionsIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "Geofencing event occured");
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        Log.e(TAG, "Location Services error: " + geofencingEvent.getErrorCode());
        return;
    }
    Log.i(TAG, "Location Services geofencingEvent: " + geofencingEvent);

    int transitionType = geofencingEvent.getGeofenceTransition();

    List<Geofence> triggeredGeofences = geofencingEvent.getTriggeringGeofences();

    for (Geofence geofence : triggeredGeofences) {
        Log.d(TAG, "onHandle:" + geofence.getRequestId());
        processGeofence(geofence, transitionType);
    }
}
项目:TrekIndiaMobile    文件:UtilityService.java   
/**
 * Called when a geofence is triggered
 */
private void geofenceTriggered(Intent intent) {
    Log.v(TAG, ACTION_GEOFENCE_TRIGGERED);

    // Check if geofences are enabled
    boolean geofenceEnabled = Utils.getGeofenceEnabled(this);

    // Extract the geofences from the intent
    GeofencingEvent event = GeofencingEvent.fromIntent(intent);
    List<Geofence> geofences = event.getTriggeringGeofences();

    if (geofenceEnabled && geofences != null && geofences.size() > 0) {
        if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER) {
            // Trigger the notification based on the first geofence
            showNotification(geofences.get(0).getRequestId(), Constants.USE_MICRO_APP);
        } else if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_EXIT) {
            // Clear notifications
            clearNotificationInternal();
            clearRemoteNotifications();
        }
    }
    UtilityReceiver.completeWakefulIntent(intent);
}
项目:io2015-codelabs    文件:UtilityService.java   
/**
 * Called when a geofence is triggered
 */
private void geofenceTriggered(Intent intent) {
    Log.v(TAG, ACTION_GEOFENCE_TRIGGERED);

    // Check if geofences are enabled
    boolean geofenceEnabled = Utils.getGeofenceEnabled(this);

    // Extract the geofences from the intent
    GeofencingEvent event = GeofencingEvent.fromIntent(intent);
    List<Geofence> geofences = event.getTriggeringGeofences();

    if (geofenceEnabled && geofences != null && geofences.size() > 0) {
        if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER) {
            // Trigger the notification based on the first geofence
            showNotification(geofences.get(0).getRequestId(), Constants.USE_MICRO_APP);
        } else if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_EXIT) {
            // Clear notifications
            clearNotificationInternal();
            clearRemoteNotifications();
        }
    }
    UtilityReceiver.completeWakefulIntent(intent);
}
项目:io2015-codelabs    文件:UtilityService.java   
/**
 * Called when a geofence is triggered
 */
private void geofenceTriggered(Intent intent) {
    Log.v(TAG, ACTION_GEOFENCE_TRIGGERED);

    // Check if geofences are enabled
    boolean geofenceEnabled = Utils.getGeofenceEnabled(this);

    // Extract the geofences from the intent
    GeofencingEvent event = GeofencingEvent.fromIntent(intent);
    List<Geofence> geofences = event.getTriggeringGeofences();

    if (geofenceEnabled && geofences != null && geofences.size() > 0) {
        if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER) {
            // Trigger the notification based on the first geofence
            showNotification(geofences.get(0).getRequestId(), Constants.USE_MICRO_APP);
        } else if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_EXIT) {
            // Clear notifications
            clearNotificationInternal();
            clearRemoteNotifications();
        }
    }
    UtilityReceiver.completeWakefulIntent(intent);
}
项目:CodenameOne    文件:GeofenceHandler.java   
@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);
        }
    }

}
项目:Geoclock    文件:GeofenceReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    final ActiveAlarmManager activeAlarmManager = new ActiveAlarmManager(context);

    GeofencingEvent event = GeofencingEvent.fromIntent(intent);
    if (event.hasError()) {
        final String errorMessage = GeofenceStatusCodes.getStatusCodeString(event.getErrorCode());
        Log.e(TAG, errorMessage);
        return;
    }

    final int transition = event.getGeofenceTransition();
    final List<Geofence> affectedGeofences = event.getTriggeringGeofences();

    if (null != affectedGeofences && !affectedGeofences.isEmpty()) {
        final Collection<GeoAlarm> affectedAlarms = filter(
                Lists.transform(affectedGeofences, getGeoAlarmForGeofenceFn(context)), a -> a != null);
        ImmutableSet<UUID> affectedAlarmIds = ImmutableSet.copyOf(transform(affectedAlarms, alarm -> alarm.id));
        if (transition == Geofence.GEOFENCE_TRANSITION_ENTER) {
            activeAlarmManager.addActiveAlarms(affectedAlarmIds);
        } else {
            activeAlarmManager.removeActiveAlarms(affectedAlarmIds);
        }
    }
}
项目:GitHub    文件:GeofenceBroadcastReceiver.java   
@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);
}
项目:Shush    文件:GeofenceBroadcastReceiver.java   
/***
 * Handles the Broadcast message sent when the Geofence Transition is triggered
 * Careful here though, this is running on the main thread so make sure you start an AsyncTask for
 * anything that takes longer than say 10 second to run
 *
 * @param context
 * @param intent
 */
@Override
public void onReceive(Context context, Intent intent) {
    //get the geofencing event sent from the intent
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);

    if (geofencingEvent.hasError()) {
        Log.e(LOG_TAG, String.format("Error Code : %s", geofencingEvent.getErrorCode()));
        return;
    }

    //get the transition type
    int geoFenceTransition = geofencingEvent.getGeofenceTransition();

    //Check which transition type has triggered the event
    if (geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) {
        RingerUtils.setRingerMode(context, AudioManager.RINGER_MODE_SILENT);
    } else if (geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
        RingerUtils.setRingerMode(context, AudioManager.RINGER_MODE_NORMAL);
    } else {
        Log.e(LOG_TAG, String.format("Unknown Transition , %d", geoFenceTransition));
        return;
    }

    //Send the notification
    sendNotification(context, geoFenceTransition);
}
项目:hypertrack-live-android    文件:GeofenceTransitionsIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
        if (geofencingEvent.hasError()) {
            String errorMessage = ErrorMessages.getGeofenceErrorString(this,
                    geofencingEvent.getErrorCode());
            HyperLog.e(TAG, errorMessage);
            return;
        }

        // Get the transition type.
        int geofenceTransition = geofencingEvent.getGeofenceTransition();
        if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) {
            HyperLog.i(TAG, "User is dwelling in geo fence.");
            ActionManager.getSharedManager(getApplicationContext()).OnGeoFenceSuccess();

        } else {
            // Log the error.
            HyperLog.e(TAG, getString(R.string.geofence_transition_invalid_type,
                    geofenceTransition));
        }

        // Get the geofences that were triggered. A single event can trigger
        // multiple geofences.
        String geofenceTransitionDetails = getGeofenceTransitionDetails(geofenceTransition,
                geofencingEvent.getTriggeringGeofences());

        HyperLog.i(TAG, "GeoFenceTransition Details: " + geofenceTransitionDetails);
    }
}
项目:GeoFencer    文件:PlayTransitionReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    notification = new SimpleNotification(context);

    if (geofencingEvent != null && !geofencingEvent.hasError()) {
        handleReceivedEventOnBackgroundThread(geofencingEvent);
    } else {
        // we end up here e.g. when the user deactivates GPS on the device
        ToastLog.warnLong(context, TAG, "Error: " + geofencingEvent.getErrorCode());
    }
}
项目:GeoFencer    文件:GeofenceUtils.java   
public static String transitionString(@NonNull final GeofencingEvent geofencingEvent) {
    int transitionCode = geofencingEvent.getGeofenceTransition();
    if (transitionCode == Geofence.GEOFENCE_TRANSITION_EXIT)
        return "EXIT";
    else if (transitionCode == Geofence.GEOFENCE_TRANSITION_ENTER)
        return "ENTER";
    else if (transitionCode == Geofence.GEOFENCE_TRANSITION_DWELL)
        return "DWELL";
    else
        return "UNKNOWN";
}
项目:MyGeofencer    文件:GeofenceTransitionsIntentService.java   
/**
 * 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 onHandleIntent(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(
                this,
                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));
    }
}
项目:EarthquakeSurvival    文件:GeofenceService.java   
@Override
protected void onHandleIntent(Intent intent) {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);

    // if the event has an error - log the textual info about it
    if (geofencingEvent.hasError()) {
        String textualError = LocationUtils.getErrorString(this, geofencingEvent.getErrorCode());
        Log.e(TAG, "onHandleIntent: " + textualError);
        return;
    }

    // extract geofence event
    int transition = geofencingEvent.getGeofenceTransition();

    if (transition == Geofence.GEOFENCE_TRANSITION_ENTER ||
            transition == Geofence.GEOFENCE_TRANSITION_EXIT) {

        List<Geofence> geoEvents = geofencingEvent.getTriggeringGeofences();

        // Get the transition details as a String.
        List<String> geofenceDetails = LocationUtils
                .getTransitionDetails(this, transition, geoEvents);

        if (Utilities.getNotificationsPrefs(getBaseContext())
                && geofenceDetails != null && geofenceDetails.size() > 0) {
            sendNotification(geofenceDetails);
        }

    } else {
        Log.e(TAG, getString(R.string.geofence_error_invalid_type, transition));
    }
}
项目:Didgeridone-Android    文件:GeofenceTransitionsIntentService.java   
/**
 * 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 onHandleIntent(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(
                this,
                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));
    }
}
项目:androidprojectbase    文件:GeofenceTransitionsIntentService.java   
/**
 * 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 onHandleIntent(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();

        // Send notification and log the transition details.
        // sendNotification(geofenceTransitionDetails);
        Intent geofenceIntent = new Intent(GeoFenceUtil.BROADCAST_INTENT_ACTION);
        geofenceIntent.putExtra(GeoFenceUtil.TRANSITION_EXTRA_ID, geofenceTransition);
        geofenceIntent.putExtra(GeoFenceUtil.LOCATION_EXTRA_ID, geofencingEvent.getTriggeringLocation());
        geofenceIntent.putExtra(GeoFenceUtil.GEOFENCES_EXTRA_ID, triggeringGeofences.get(0).getRequestId());
        sendBroadcast(geofenceIntent);

    } else {
        // Log the error.
        Log.e(TAG, "Invalid transition type");
    }
}
项目:mobile-messaging-sdk-android    文件:GeoTransitionHelper.java   
/**
 * 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()));
}
项目:android-wg-planer    文件:GeofenceTransitionsIntentService.java   
protected void onHandleIntent(Intent intent) {
    Log.d(MainActivity.TAG, "onHandleIntent(" + intent + ")");
    Lesson nearestLesson = getNearestLesson(true);
    if (intent.hasExtra(EXTRA_TRANSITION) && intent.hasExtra(EXTRA_GEOFENCE_LIST) && intent.hasExtra(EXTRA_TRIGGERING_LOCATION)) {
        GeofencingEvent geoFenceEvent = GeofencingEvent.fromIntent(intent);
        if (geoFenceEvent.hasError()) {
            int errorCode = geoFenceEvent.getErrorCode();
            Log.e(MainActivity.TAG, "Location Services error: " + errorCode);
            cancelSelf();
            setSilent(false);
        } else {
            int transitionType = geoFenceEvent.getGeofenceTransition();
            if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER) {
                setSilent(true);
                sendNotificationIfNeeded(nearestLesson);
            } else if (transitionType == Geofence.GEOFENCE_TRANSITION_EXIT) {
                cancelSelf();
                setSilent(false);
            }
        }
    } else if (intent.hasExtra(EXTRA_TRIGGERED_SELF) && intent.getBooleanExtra(EXTRA_TRIGGERED_SELF, false)) {
        sendNotificationIfNeeded(nearestLesson);
    } else {
        cancelSelf();
        setSilent(false);
    }
}
项目:LETO-Toggl_Android    文件:GeofenceTransitionsIntentService.java   
/**
     * 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 onHandleIntent(Intent intent) {
        GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
        if (geofencingEvent.hasError()) {
            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(
                    this,
                    geofenceTransition,
                    triggeringGeofences
            );

            // Send notification and log the transition details.
//            sendNotification(geofenceTransitionDetails);
            Log.i(TAG, geofenceTransitionDetails);
        } else {
            // Log the error.
            Log.e(TAG, "INVALID");
        }
    }
项目:orchextra-android-sdk    文件:AndroidGeofenceIntentServiceHandler.java   
public List<String> getTriggeringGeofenceIds(GeofencingEvent geofencingEvent) {
    List<String> triggerGeofenceIds = new ArrayList<>();

    if (geofencingEvent == null) {
        return Collections.emptyList();
    }

    List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
    if (triggeringGeofences != null) {
        for (Geofence triggeringGeofence : triggeringGeofences) {
            triggerGeofenceIds.add(triggeringGeofence.getRequestId());
        }
    }
    return triggerGeofenceIds;
}
项目:orchextra-android-sdk    文件:AndroidGeofenceIntentServiceHandler.java   
public GeoPointEventType getGeofenceTransition(GeofencingEvent geofencingEvent) {
    if (!geofencingEvent.hasError()) {
        int transition = geofencingEvent.getGeofenceTransition();
        switch (transition) {
            case Geofence.GEOFENCE_TRANSITION_ENTER:
                return GeoPointEventType.ENTER;
            case Geofence.GEOFENCE_TRANSITION_DWELL:
                return GeoPointEventType.STAY;
            case Geofence.GEOFENCE_TRANSITION_EXIT:
                return GeoPointEventType.EXIT;
        }
    }
    throw new GeofenceEventException("Geofence Event Error was produced, code is: " + geofencingEvent.getErrorCode());
}
项目:ProfileManager    文件:GeofenceTransitionIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "onHandle");
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        String errorMessage =
                GeofenceErrorMessage.getErrorString(this, geofencingEvent.getErrorCode());
        Log.e(TAG, errorMessage);
        return;
    }

    mProfileManagerSharedPref = ProfileManagerSharedPref.gcSharedPreferenceInstance(this);
    // 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(this, geofenceTransition, triggeringGeofences);
        Log.i(TAG, geofenceTransitionDetails);
    } else {
        // Logger the error.
        Log.e(TAG, getString(R.string.geofence_transition_invalid_type, geofenceTransition));
    }
}
项目:GeofenceHelper    文件:DefaultTransitionsIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    String notificationText = "Not a geo event";
    GeofencingEvent geoEvent = GeofencingEvent.fromIntent(intent);
    if (geoEvent != null) {
        if (geoEvent.hasError()) {
            notificationText = "Error : " + geoEvent.getErrorCode();
        } else {
            int transition = geoEvent.getGeofenceTransition();
            String transitionStr;
            switch (transition) {
                case Geofence.GEOFENCE_TRANSITION_ENTER:
                    transitionStr = "Enter-";
                    break;
                case Geofence.GEOFENCE_TRANSITION_EXIT:
                    transitionStr = "Exit-";
                    break;
                case Geofence.GEOFENCE_TRANSITION_DWELL:
                    transitionStr = "Dwell-";
                    break;
                default:
                    transitionStr = "Unknown-";
            }

            List<Geofence> triggeringGeo = geoEvent.getTriggeringGeofences();

            StringBuilder strBuilder = new StringBuilder();
            strBuilder.append(transitionStr);
            for (int i = 0; i < triggeringGeo.size(); i++) {
                Geofence geo = triggeringGeo.get(i);
                strBuilder.append(geo.getRequestId());
                strBuilder.append("-");
            }
            notificationText = strBuilder.toString();
        }
    }

    sendNotification(notificationText);
}
项目:PowerSwitch_Android    文件:GeofenceIntentService.java   
/**
 * 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 onHandleIntent(Intent intent) {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        Log.e(this, "GeofencingError");
        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 Ids of each geofence that was triggered.
        ArrayList<String> triggeringGeofencesIdsList = new ArrayList<>();
        for (Geofence geofence : triggeringGeofences) {
            triggeringGeofencesIdsList.add(geofence.getRequestId());
        }
        Log.d(this, getTransitionString(geofenceTransition) + ": " + TextUtils.join(", ", triggeringGeofencesIdsList));

        executeGeofences(triggeringGeofences, geofenceTransition);
    } else {
        // Log the error.
        Log.e(this, "Unknown Geofence transition: " + geofenceTransition);
    }
}
项目:buseta    文件:GeofenceTransitionsIntentService.java   
/**
 * 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 onHandleIntent(Intent intent) {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        Timber.e("GeofenceError: %s", geofencingEvent.getErrorCode());
        return;
    }
    int transition = geofencingEvent.getGeofenceTransition();
    if (transition == Geofence.GEOFENCE_TRANSITION_ENTER ||
            transition == Geofence.GEOFENCE_TRANSITION_EXIT) {

        List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();

        for (Geofence geofence: triggeringGeofences) {
            sendNotification(geofence.getRequestId().hashCode(),
                    getTransitionString(transition), geofence.getRequestId());
        }

        // remove current geofences key
        PreferenceManager.getDefaultSharedPreferences(this)
                .edit()
                .putString(C.PREF.GEOFENCES_KEY, "")
                .apply();
    } else {
        Timber.d("GeofenceError: %s", transition);
    }
}
项目:io2015-codelabs    文件:GeofenceTransitionsIntentService.java   
@Override
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;
    }

    // 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(
                this,
                geofenceTransition,
                triggeringGeofences
        );

        // Send notification and log the transition details.
        sendNotification(geofenceTransitionDetails);
        Log.i(TAG, geofenceTransitionDetails);
    } else {
        // Log the error.
    }
}
项目:FenceHouston    文件:GeofenceIntentService.java   
@Override
    protected void onHandleIntent(Intent intent) {
        GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
        Log.v(TAG, "onHandleIntent");
        if(!geofencingEvent.hasError()) {
            int transition = geofencingEvent.getGeofenceTransition();
            String notificationTitle = " ";

            switch(transition) {
                case Geofence.GEOFENCE_TRANSITION_ENTER:
                    notificationTitle = "Tap For More Info About:";
//                    Log.v(TAG, "Geofence Entered");
                    sendNotification(this, getTriggeringGeofences(intent), notificationTitle);
                    break;
                case Geofence.GEOFENCE_TRANSITION_DWELL:
                    notificationTitle = "Geofence Dwell";
                    Log.v(TAG, "Dwelling in Geofence");
                    break;
                case Geofence.GEOFENCE_TRANSITION_EXIT:
//                    notificationTitle = "Geofence Exit";
//                    Log.v(TAG, "Geofence Exited");
//                    sendNotification(this, getTriggeringGeofences(intent), notificationTitle);
                    break;
                default:
                    notificationTitle = "Geofence Unknown";
            }

            //sendNotification(this, getTriggeringGeofences(intent), notificationTitle);
        }
    }
项目:FenceHouston    文件:GeofenceIntentService.java   
private String getTriggeringGeofences(Intent intent) {
    GeofencingEvent geofenceEvent = GeofencingEvent.fromIntent(intent);
    List<Geofence> geofences = geofenceEvent
            .getTriggeringGeofences();

    String[] geofenceIds = new String[geofences.size()];

    for (int i = 0; i < geofences.size(); i++) {
        geofenceIds[i] = geofences.get(i).getRequestId();
    }

    return TextUtils.join(", ", geofenceIds);
}
项目:cominghome    文件:GeofenceTransitionsIntentService.java   
/**
 * 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 onHandleIntent(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
        );

        if (debug) Log.d(TAG, geofenceTransitionDetails);
        FenceHandling.process(geofenceTransition, triggeringGeofences,
                geofencingEvent.getTriggeringLocation(), getApplicationContext());

    } else {
        // Log the error.
        Log.e(TAG, getString(R.string.geofence_transition_invalid_type, geofenceTransition));
    }
}
项目:android-play-location    文件:GeofenceTransitionsJobIntentService.java   
/**
 * 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));
    }
}
项目:1617PROJ1Bloeddonatie-app    文件:GeofenceService.java   
@Override
protected void onHandleIntent(Intent intent) {


    GeofencingEvent event = GeofencingEvent.fromIntent(intent);
    if (event.hasError()) {
        Log.d(TAG, "error");
    } else {
        int transition = event.getGeofenceTransition();
        List<Geofence> geofences = event.getTriggeringGeofences();
        Geofence geofence = geofences.get(0);
        String requestId = geofence.getRequestId();

        Date today = new Date();
        String currentDate = sdf.format(today);

        SharedPreferences sharedPreferences = getSharedPreferences("dates", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        String savedDate = sharedPreferences.getString(requestId, null);

        if (savedDate == null) {
            editor.putString(requestId, currentDate);
            editor.apply();
            testTranistion(transition,requestId);
        } else {
            try {
                Date previousDate = sdf.parse(savedDate);
                Calendar c1 = Calendar.getInstance();
                Calendar c2 = Calendar.getInstance();
                c1.setTime(today);
                c2.setTime(previousDate);

                if ((c1.getTimeInMillis() - c2.getTimeInMillis()) / (24 * 60 * 60 * 1000) >= 30) {
                    editor.putString(requestId, currentDate);
                    editor.apply();
                    testTranistion(transition,requestId);
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }


    }
}
项目:GeoFencer    文件:PlayTransitionReceiver.java   
private void handleReceivedEventOnBackgroundThread(@NonNull final GeofencingEvent geofencingEvent) {
    String content = String.format("%s: %s",
            DateUtils.getTimestamptString(),
            GeofenceUtils.transitionString(geofencingEvent));
    notification.show(new Random().nextInt(), content);
}
项目:react-native-region-monitor    文件:RNRegionTransitionService.java   
@Override
@Nullable
protected HeadlessJsTaskConfig getTaskConfig(Intent intent)
{
    if (intent.getExtras() == null)
    {
        return null;
    }

    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);

    if (geofencingEvent.hasError())
    {
        // Suppress geofencing event with error
        Log.d(TAG, "Suppress geocoding event with error");
        return null;
    }

    WritableMap location = Arguments.createMap();
    location.putDouble("latitude", geofencingEvent.getTriggeringLocation().getLatitude());
    location.putDouble("longitude", geofencingEvent.getTriggeringLocation().getLongitude());

    WritableMap region = Arguments.createMap();
    region.putString("identifier", geofencingEvent.getTriggeringGeofences().get(0).getRequestId());

    WritableArray regionIdentifiers = Arguments.createArray();
    for (Geofence triggered: geofencingEvent.getTriggeringGeofences())
    {
        regionIdentifiers.pushString(triggered.getRequestId());
    }
    region.putArray("identifiers", regionIdentifiers);

    WritableMap jsArgs = Arguments.createMap();
    jsArgs.putMap("location", location);
    jsArgs.putMap("region", region);
    jsArgs.putBoolean("didEnter", geofencingEvent.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER);
    jsArgs.putBoolean("didExit", geofencingEvent.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_EXIT);
    //jsArgs.putBoolean("didDwell", geofencingEvent.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_DWELL);

    Log.d(TAG, "Report geofencing event to JS: " + jsArgs);
    return new HeadlessJsTaskConfig(RNRegionMonitorModule.TRANSITION_TASK_NAME, jsArgs, 0, true);
}
项目:react-native-geo-fence    文件:GeofenceTransitionsIntentService.java   
/**
 * 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 onHandleIntent(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();
        WritableArray writableArray = new WritableNativeArray();

        for (int i = 0; i < triggeringGeofences.size(); i++) {
            Geofence geofence = triggeringGeofences.get(i);
            String key = geofence.getRequestId();
            ReadableMap geofenceMap = getGeofenceFromKey(key);
            WritableMap writableMap = new WritableNativeMap();
            writableMap.merge(geofenceMap);
            writableMap.putString("transition", getTransitionString(geofenceTransition));
            writableArray.pushMap(writableMap);
        }

        // create final event emitter object argument
        WritableMap finalEventEmitterObject = new WritableNativeMap();
        finalEventEmitterObject.putArray("data", writableArray);
        finalEventEmitterObject.putString("event", "geofenceTrigger");

        SReactApplicationContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit("GeofenceEvent", finalEventEmitterObject);
    } else {
        // Log the error.
        Log.e(TAG, "Geofence transition error: invalid transition type " + geofenceTransition);
    }
}