コード例 #1
0
        protected override void OnHandleIntent(Intent intent)
        {
            var geofencingEvent = GeofencingEvent.FromIntent(intent);

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

            var geofenceTransition = geofencingEvent.GeofenceTransition;

            if (geofenceTransition == Geofence.GeofenceTransitionEnter ||
                geofenceTransition == Geofence.GeofenceTransitionExit)
            {
                var triggeringGeofences = geofencingEvent.TriggeringGeofences;

                var 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) }));
            }
        }
コード例 #2
0
        public void OnResult(Java.Lang.Object x0)
        {
            var status = (Statuses)x0;

            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);
            }
        }
コード例 #3
0
        public void OnComplete(Task task)
        {
            mPendingGeofenceTask = PendingGeofenceTask.NONE;
            if (task.IsSuccessful)
            {
                UpdateGeofencesAdded(!GetGeofencesAdded());
                SetButtonsEnabledState();

                var messageId = GetGeofencesAdded() ? Resource.String.geofences_added : Resource.String.geofences_removed;
                Toast.MakeText(this, GetString(messageId), ToastLength.Short).Show();
            }
            else
            {
                var errorMessage = GeofenceErrorMessages.GetErrorString(this, task.Exception);
                Log.Warn(TAG, errorMessage);
            }
        }