Example #1
0
        public void HandleResult(Statuses status)
        {
            if (status.IsSuccess)
            {
                mGeofencesAdded = !mGeofencesAdded;
                var editor = mSharedPreferences.Edit();
                editor.PutBoolean(Constants.GEOFENCES_ADDED_KEY, mGeofencesAdded);
                editor.Commit();

                SetButtonsEnabledState();

                Toast.MakeText(
                    this,
                    GetString(mGeofencesAdded ? Resource.String.geofences_added :
                              Resource.String.geofences_removed),
                    ToastLength.Short
                    ).Show();
            }
            else
            {
                var errorMessage = GeofenceErrorMessages.GetErrorString(this,
                                                                        status.StatusCode);
                Log.Error(TAG, errorMessage);
            }
        }
Example #2
0
      public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
      {
          var geofencingEvent = GeofencingEvent.FromIntent(intent);

          if (geofencingEvent.HasError)
          {
              var errorMessage = GeofenceErrorMessages.GetErrorString(this, geofencingEvent.ErrorCode);
              Log.Error(TAG, errorMessage);
              return(StartCommandResult.NotSticky);;
          }

          int geofenceTransition = geofencingEvent.GeofenceTransition;

          if (geofenceTransition == Geofence.GeofenceTransitionEnter ||
              geofenceTransition == Geofence.GeofenceTransitionExit)
          {
              IList <IGeofence> triggeringGeofences = geofencingEvent.TriggeringGeofences;

              string geofenceTransitionDetails = GetGeofenceTransitionDetails(this, geofenceTransition, triggeringGeofences);

              SendNotification(geofenceTransitionDetails);
              Log.Info(TAG, geofenceTransitionDetails);
          }
          else
          {
              // Log the error.
              Log.Error(TAG, GetString(Resource.String.geofence_transition_invalid_type, new[] { new Java.Lang.Integer(geofenceTransition) }));
          }
          return(StartCommandResult.RedeliverIntent);
      }