Java Code Examples for com.google.android.gms.location.GeofencingEvent#getErrorCode()
The following examples show how to use
com.google.android.gms.location.GeofencingEvent#getErrorCode() .
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 |
@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: ReceiveTransitionsIntentService.java From Leanplum-Android-SDK with Apache License 2.0 | 6 votes |
@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); } }
Example 3
Source File: GeofenceData.java From android-sdk with MIT License | 6 votes |
private static String check(GeofencingEvent event) { if (event == null) { return "GeofencingEvent is null"; } if (event.hasError()) { return "GeofencingEvent has error: "+event.getErrorCode(); } if (event.getTriggeringGeofences() == null) { return "GeofencingEvent has no triggering geofences"; } if (event.getTriggeringGeofences().isEmpty()) { return "GeofencingEvent has empty list of triggering geofences"; } int transition = event.getGeofenceTransition(); //Only GEOFENCE_TRANSITION_ENTER and GEOFENCE_TRANSITION_EXIT are supported for now. if (transition != Geofence.GEOFENCE_TRANSITION_ENTER && transition != Geofence.GEOFENCE_TRANSITION_EXIT) { return "GeofencingEvent has invalid transition: "+transition; } return null; }
Example 4
Source File: GeoTransitionHelper.java From mobile-messaging-sdk-android with Apache License 2.0 | 5 votes |
/** * 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 5
Source File: GeofenceTransitionsIntentService.java From android-Geofencing with Apache License 2.0 | 4 votes |
/** * Handles incoming intents. * @param intent The 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 geoFenceEvent = GeofencingEvent.fromIntent(intent); if (geoFenceEvent.hasError()) { int errorCode = geoFenceEvent.getErrorCode(); Log.e(TAG, "Location Services error: " + errorCode); } else { int transitionType = geoFenceEvent.getGeofenceTransition(); if (Geofence.GEOFENCE_TRANSITION_ENTER == transitionType) { // Connect to the Google Api service in preparation for sending a DataItem. mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); // Get the geofence id triggered. Note that only one geofence can be triggered at a // time in this example, but in some cases you might want to consider the full list // of geofences triggered. String triggeredGeoFenceId = geoFenceEvent.getTriggeringGeofences().get(0) .getRequestId(); // Create a DataItem with this geofence's id. The wearable can use this to create // a notification. final PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(GEOFENCE_DATA_ITEM_PATH); putDataMapRequest.getDataMap().putString(KEY_GEOFENCE_ID, triggeredGeoFenceId); putDataMapRequest.setUrgent(); if (mGoogleApiClient.isConnected()) { Wearable.DataApi.putDataItem( mGoogleApiClient, putDataMapRequest.asPutDataRequest()).await(); } else { Log.e(TAG, "Failed to send data item: " + putDataMapRequest + " - Client disconnected from Google Play Services"); } Toast.makeText(this, getString(R.string.entering_geofence), Toast.LENGTH_SHORT).show(); mGoogleApiClient.disconnect(); } else if (Geofence.GEOFENCE_TRANSITION_EXIT == transitionType) { // Delete the data item when leaving a geofence region. mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); Wearable.DataApi.deleteDataItems(mGoogleApiClient, GEOFENCE_DATA_ITEM_URI).await(); showToast(this, R.string.exiting_geofence); mGoogleApiClient.disconnect(); } } }