protected override void OnHandleIntent(Intent intent) { var action = intent != null ? intent.Action : null; if (action == actionAddGeoFences) { AddGeofencesInternal(); } else if (action == ActionGeofenceTriggered) { GeofenceTriggered(intent); } else if (action == actionRequestLocation) { RequestLocationInternal(); } else if (action == actionLocationUpdated) { LocationUpdated(intent); } else if (action == actionClearNotification) { ClearNotificationInternal(); } else if (action == actionClearRemoteNotifications) { ClearRemoteNotifications(); } else if (action == actionFakeUpdate) { var currentLocation = Utils.GetLocation(this); // If location unknown use test city, otherwise use closest city string city = currentLocation == null ? TouristAttractionsHelper.TestCity : TouristAttractionsHelper.GetClosestCity(currentLocation); ShowNotification(city, intent.GetBooleanExtra(extraTestMicroApp, Constants.UseMicroApp)); } }
/** * Add geofences using Play Services */ private async void AddGeofencesInternal() { Log.Verbose("UtilityService", actionAddGeoFences); if (!Utils.CheckFineLocationPermission(this)) { return; } GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .AddApi(LocationServices.API) .Build(); // It's OK to use blockingConnect() here as we are running in an // IntentService that executes work on a separate (background) thread. ConnectionResult connectionResult = googleApiClient.BlockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.Seconds); if (connectionResult.IsSuccess && googleApiClient.IsConnected) { var pendingIntent = PendingIntent.GetBroadcast( this, 0, new Intent(this, typeof(UtilityReceiver)), 0); //TODO: Move to new api var status = await LocationServices.GeofencingApi.AddGeofencesAsync(googleApiClient, TouristAttractionsHelper.GetGeofenceList(), pendingIntent); googleApiClient.Disconnect(); } else { Log.Error("UtilityService", string.Format(Constants.GOOGLE_API_CLIENT_ERROR_MSG, connectionResult.ErrorCode)); } }