com.google.android.gms.location.GeofenceStatusCodes Java Examples

The following examples show how to use com.google.android.gms.location.GeofenceStatusCodes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeofenceBroadcastReceiver.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
  GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);

  if (geofencingEvent.hasError()) {
    int errorCode = geofencingEvent.getErrorCode();
    String errorMessage = GeofenceStatusCodes.getStatusCodeString(errorCode);
    Log.e(TAG, errorMessage);
  } else {
    // Get the transition type.
    int geofenceTransition = geofencingEvent.getGeofenceTransition();

    // A single event can trigger multiple geofences.
    // Get the geofences that were triggered.
    List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();

    // TODO React to the Geofence(s) transition(s).
  }
}
 
Example #2
Source File: GeofenceErrorMessages.java    From react-native-boundary with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the error string for a geofencing error code.
 */
public static String getErrorString(int errorCode) {
    switch (errorCode) {
        case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE:
            return "Geofence is not available";
        case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES:
            return "Too many geofences";
        case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS:
            return "Too many pending intents";
        default:
            return "Unknown error: " + Integer.toString(errorCode);
    }
}
 
Example #3
Source File: GeoTransitionHelper.java    From mobile-messaging-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * 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()));
}
 
Example #4
Source File: GeofenceErrorMessages.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
public static String getErrorString(Context context, int errorCode) {
    Resources mResources = context.getResources();
    switch (errorCode) {
        case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE:
            return "Geofence service is not available now.";
        case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES:
            return "Your app has registered too many geofences.";
        case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS:
            return "You have provided too many PendingIntents!";
        default:
            return "Unknown error.";
    }
}
 
Example #5
Source File: GeofenceErrorMessages.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
public static String getErrorString(Context context, int errorCode) {
    Resources mResources = context.getResources();
    switch (errorCode) {
        case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE:
            return "Geofence service is not available now.";
        case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES:
            return "Your app has registered too many geofences.";
        case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS:
            return "You have provided too many PendingIntents!";
        default:
            return "Unknown error.";
    }
}
 
Example #6
Source File: GeofenceErrorMessages.java    From location-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the error string for a geofencing error code.
 */
public static String getErrorString(Context context, int errorCode) {
    Resources mResources = context.getResources();
    switch (errorCode) {
        case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE:
            return mResources.getString(R.string.geofence_not_available);
        case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES:
            return mResources.getString(R.string.geofence_too_many_geofences);
        case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS:
            return mResources.getString(R.string.geofence_too_many_pending_intents);
        default:
            return mResources.getString(R.string.unknown_geofence_error);
    }
}
 
Example #7
Source File: NativeLocationClientImpl.java    From android_external_GmsLib with Apache License 2.0 4 votes vote down vote up
public void addGeofences(GeofencingRequest geofencingRequest, PendingIntent pendingIntent, IGeofencerCallbacks callbacks) throws RemoteException {
    Log.d(TAG, "addGeofences(GeofencingRequest)");
    callbacks.onAddGeofenceResult(GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE, new String[0]);
}
 
Example #8
Source File: NativeLocationClientImpl.java    From android_external_GmsLib with Apache License 2.0 4 votes vote down vote up
public void removeGeofences(List<String> requestIds, IGeofencerCallbacks callbacks) throws RemoteException {
    Log.d(TAG, "removeGeofences(List<RequestId>)");
    callbacks.onRemoveGeofencesByRequestIdsResult(GeofenceStatusCodes.ERROR, requestIds.toArray(new String[requestIds.size()]));
}