Exemplo n.º 1
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);
      }
Exemplo n.º 2
0
        /**
         * Called when a geofence is triggered
         */
        private async void GeofenceTriggered(Intent intent)
        {
            Log.Verbose("UtilityService", ActionGeofenceTriggered);

            // Check if geofences are enabled
            bool geofenceEnabled = Utils.GetGeofenceEnabled(this);

            // Extract the geofences from the intent
            var geoEvent  = GeofencingEvent.FromIntent(intent);
            var geofences = geoEvent.TriggeringGeofences;

            if (geofenceEnabled && geofences != null && geofences.Count > 0)
            {
                if (geoEvent.GeofenceTransition == Geofence.GeofenceTransitionEnter)
                {
                    //TODO:
                    // Trigger the notification based on the first geofence
                    //ShowNotification(geofences.get(0).getRequestId(), Constants.USE_MICRO_APP);
                }
                else if (geoEvent.GeofenceTransition == Geofence.GeofenceTransitionExit)
                {
                    // Clear notifications
                    ClearNotificationInternal();
                    await ClearRemoteNotifications();
                }
            }
            Android.Support.V4.Content.WakefulBroadcastReceiver.CompleteWakefulIntent(intent);
        }
Exemplo n.º 3
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::OnStartCommand received. Returning Sticky"));

            // is this being called by Location Services?
            GeofencingEvent geoEvent = GeofencingEvent.FromIntent(intent);

            if (geoEvent != null && geoEvent.TriggeringLocation != null)
            {
                // if the location service api is connected, process the event now
                if (ILocationServiceApi.IsConnected)
                {
                    HandleGeofencingEvent(geoEvent);
                }
                else
                {
                    // then store the event as pending
                    PendingGeofenceEvent = geoEvent;

                    // otherwise establish a google api connection and when it calls us back we'll
                    // process this event.
                    ILocationServiceApi.Connect( );
                }
            }

            return(StartCommandResult.Sticky);
        }
        protected override void OnHandleIntent(Intent intent)
        {
            var geofencingEvent = GeofencingEvent.FromIntent(intent);

            if (geofencingEvent.HasError)
            {
                var errorMessage = GeofenceErrorMessages.GetErrorString(this, geofencingEvent.ErrorCode);
                Console.WriteLine(errorMessage);
                return;
            }

            int geofenceTransition = geofencingEvent.GeofenceTransition;

            if (geofenceTransition == Geofence.GeofenceTransitionEnter ||
                geofenceTransition == Geofence.GeofenceTransitionExit)
            {
                transitionState = GetTransitionString(geofenceTransition);
                IList <IGeofence> triggeringGeofences       = geofencingEvent.TriggeringGeofences;
                string            geofenceTransitionDetails = GetGeofenceTransitionDetails(this, geofenceTransition, triggeringGeofences);
                transitionState = GetTransitionString(geofenceTransition);
                // Call Geofence Broadcast Receiver
                Intent i = new Intent("transition_change");
                i.PutExtra("Transition", transitionState);
                i.PutExtra("GeofenceId", GetGeofenceString(triggeringGeofences));
                SendBroadcast(i);
            }
        }
Exemplo n.º 5
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;
            }

            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) }));
            }
        }
        protected override void OnHandleIntent(Intent intent)
        {
            if (intent == null)
            {
                return;
            }

            MvxTrace.TaggedTrace(TAG, "GeofenceTransitionsIntentService handle intent");

            var geofencingEvent = GeofencingEvent.FromIntent(intent);

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

            int geofenceTransition = geofencingEvent.GeofenceTransition;

            if (geofenceTransition != Geofence.NeverExpire)
            {
                IList <IGeofence> triggeringGeofences = geofencingEvent.TriggeringGeofences;

                var geofencesIds = GetGeofenceTransitionDetails(this, geofenceTransition, triggeringGeofences);
                LoadOffersInGeofences(geofencesIds);
            }
            else
            {
                // Log the error.
                MvxTrace.TaggedError(TAG, GetString(Resource.String.geofence_transition_invalid_type, new[] { new Java.Lang.Integer(geofenceTransition) }));
            }
        }
Exemplo n.º 7
0
        public async Task Process(Intent intent)
        {
            var e = GeofencingEvent.FromIntent(intent);

            if (e == null)
            {
                return;
            }

            foreach (var triggeringGeofence in e.TriggeringGeofences)
            {
                var region = await this.Repository.Get(triggeringGeofence.RequestId);

                if (region != null)
                {
                    var state = (GeofenceState)e.GeofenceTransition;
                    await this.geofenceDelegate.OnStatusChanged(state, region);

                    if (region.SingleUse)
                    {
                        await this.StopMonitoring(region);
                    }
                }
            }
        }
        protected override void OnHandleIntent(Intent intent)
        {
            GeofencingEvent geofencingEvent = GeofencingEvent.FromIntent(intent);

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

            int geofenceTransition = geofencingEvent.GeofenceTransition;

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

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

                SendNotification(geofenceTransitionDetails);
                Log.Info(TAG, geofenceTransitionDetails);
            }
            else
            {
                Log.Error(TAG, GetString(Resource.String.geofence_transition_invalid_type, geofenceTransition));
            }
        }
Exemplo n.º 9
0
        public override async void OnReceive(Context context, Intent intent)
        {
            if (!intent.Action.Equals(INTENT_ACTION))
            {
                return;
            }

            var e = GeofencingEvent.FromIntent(intent);

            if (e == null)
            {
                return;
            }

            var repository       = ShinyHost.Resolve <IRepository>();
            var geofences        = ShinyHost.Resolve <IGeofenceManager>();
            var geofenceDelegate = ShinyHost.Resolve <IGeofenceDelegate>();

            foreach (var triggeringGeofence in e.TriggeringGeofences)
            {
                var region = await repository.Get <GeofenceRegion>(triggeringGeofence.RequestId);

                if (region != null)
                {
                    var state = (GeofenceState)e.GeofenceTransition;
                    geofenceDelegate.OnStatusChanged(state, region);

                    if (region.SingleUse)
                    {
                        await geofences.StopMonitoring(region);
                    }
                }
            }
        }
Exemplo n.º 10
0
        internal void TryFireEvent(GeofencingEvent e)
        {
            lock (syncLock)
            {
                try
                {
                    var status = e.GeofenceTransition == Geofence.GeofenceTransitionEnter
                        ? GeofenceStatus.Entered
                        : GeofenceStatus.Exited;

                    if (e.TriggeringGeofences == null)
                    {
                        return;
                    }

                    foreach (var native in e.TriggeringGeofences)
                    {
                        var region = regions.FirstOrDefault(x => x.Identifier.Equals(native.RequestId));
                        if (region == null)
                        {
                            System.Diagnostics.Debug.WriteLine($"Triggered geofence does not exist in the list of watching geofences");
                            return;
                        }
                        region.LastKnownGeofenceStatus = status;
                        MarcelloDatabase.Current.Save(region);
                        OnRegionStatusChanged(region, status);
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine($"Error in TryFireEvent: {ex.Message}");
                }
            }
        }
Exemplo n.º 11
0
        protected override void OnHandleIntent(Intent intent)
        {
            var geofencingEvent = GeofencingEvent.FromIntent(intent);

            if (geofencingEvent.HasError)
            {
                return;
            }

            var geofenceTransition = geofencingEvent.GeofenceTransition;

            if (geofenceTransition == Geofence.GeofenceTransitionEnter ||
                geofenceTransition == Geofence.GeofenceTransitionExit)
            {
                var triggeringGeofences       = geofencingEvent.TriggeringGeofences;
                var geofenceTransitionDetails = GetGeofenceTransitionDetails(this, geofenceTransition, triggeringGeofences);
                SendNotification(geofenceTransitionDetails);

                var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=tidbankhackfest;AccountKey=zim7KI8GmnxY/ybkSQqzf6HKUw7coKNUlx7Wto7V6EsS/cLJpBY4mJLffrZd7NY6CP7DNTnV0f0SbO1G6g5+dA==;");
                var queueClient    = storageAccount.CreateCloudQueueClient();
                var queue          = queueClient.GetQueueReference("officequeue");
                if (geofenceTransition == Geofence.GeofenceTransitionEnter)
                {
                    queue.AddMessageAsync(new CloudQueueMessage("AntonS checked in")).Wait();
                }
                else
                {
                    queue.ClearAsync().Wait();
                }
            }
        }
Exemplo n.º 12
0
        // startup tasks replace this, but this receiver is still used to trigger the wakeup on reboot
        protected override async Task OnReceiveAsync(Context?context, Intent?intent)
        {
            var e = GeofencingEvent.FromIntent(intent);

            if (e != null && Process != null)
            {
                await Process(e);
            }
        }
        public async Task Process(Intent intent)
        {
            var e = GeofencingEvent.FromIntent(intent);

            if (e == null)
            {
                return;
            }


            if (e.HasError)
            {
                Log.Write(
                    LocationLogCategory.Geofence,
                    "Event Error",
                    ("ErrorCode", GeofenceStatusCodes.GetStatusCodeString(e.ErrorCode))
                    );
            }
            else if (e.TriggeringGeofences != null)
            {
                foreach (var triggeringGeofence in e.TriggeringGeofences)
                {
                    var state  = (GeofenceState)e.GeofenceTransition;
                    var region = await this.repository.Get(triggeringGeofence.RequestId);

                    if (region == null)
                    {
                        Log.Write(
                            LocationLogCategory.Geofence,
                            "Not Found",
                            ("RequestId", triggeringGeofence.RequestId)
                            );
                    }
                    else
                    {
                        try
                        {
                            await this.geofenceDelegate.OnStatusChanged(state, region);

                            if (region.SingleUse)
                            {
                                await this.geofenceManager.StopMonitoring(region.Identifier);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Write(
                                ex,
                                ("RequestId", triggeringGeofence.RequestId),
                                ("Transition", state.ToString())
                                );
                        }
                    }
                }
            }
        }
        protected override void OnHandleIntent(Intent intent)
        {
            var geofencingEvent = GeofencingEvent.FromIntent(intent);
            var dbAdapter       = new DbAdapter_Droid();

            if (geofencingEvent.HasError)
            {
                var errorMessage = GeofenceErrorMessages.GetErrorString(this, geofencingEvent.ErrorCode);
                dbAdapter.AddDeviceLog("ジオフェンスエラー", errorMessage);
                NotificationUtil.Instance.SendNotification(this, NotificationUtil.STATUS_NOTIFICATION_CHANNEL_ID, "GeofenceError", "エラーです。", errorMessage);
                return;
            }

            int geofenceTransition = geofencingEvent.GeofenceTransition;

            if (geofenceTransition == Geofence.GeofenceTransitionEnter ||
                geofenceTransition == Geofence.GeofenceTransitionExit)
            {
                IList <IGeofence> triggeringGeofences = geofencingEvent.TriggeringGeofences;
                var    updateGeofenceStatus           = geofenceTransition == Geofence.GeofenceTransitionEnter;
                string geofenceTransitionDetails      = GetGeofenceTransitionDetails(this, geofenceTransition, triggeringGeofences);
                Log.Info(TAG, geofenceTransitionDetails);

                var triggerRegions = triggeringGeofences
                                     .Select(g => Regions.RegionList.GetRegionFromIdentifier(g.RequestId))
                                     .Where(r => r != null)
                                     .Select(r => (Regions.GeofenceRegion)r)
                                     .ToList()
                ;

                //GPS情報
                var lat      = geofencingEvent.TriggeringLocation.Latitude;
                var lng      = geofencingEvent.TriggeringLocation.Longitude;
                var accuracy = geofencingEvent.TriggeringLocation.Accuracy;
                var date     = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");

                // 更新
                foreach (var region in triggerRegions)
                {
                    var statusText = geofenceTransition == Geofence.GeofenceTransitionEnter ? "侵入" : "退出";
                    dbAdapter.AddDeviceLog($"ジオフェンス[{region.DbIdentifierName}]の状態を[{statusText}]に更新", $"{date},Droid,{lat},{lng},{accuracy},{statusText}");
                    dbAdapter.UpdateGeofenceStatus(UserDataModel.Instance.DeviceId, region.DbIdentifierName, updateGeofenceStatus);
                }
            }
            else
            {
                // Log the error.
                Log.Error(TAG, this.GetString(Resource.String.geofence_transition_invalid_type, new[] { new Java.Lang.Integer(geofenceTransition) }));
                dbAdapter.AddDeviceLog("ジオフェンスエラー", this.GetString(Resource.String.geofence_transition_invalid_type, new[] { new Java.Lang.Integer(geofenceTransition) }));
            }
        }
Exemplo n.º 15
0
        protected override void OnHandleWork(Intent intent)
        {
            var geofencingEvent = GeofencingEvent.FromIntent(intent);

            if (geofencingEvent.HasError)
            {
                Log.Info("GeofenceTransitionsJobIntentService", $"{geofencingEvent.ErrorCode}");
                return;
            }

            if (CrossGeofencing.Current is GeofencingImplementation managerImpl)
            {
                managerImpl.TryFireEvent(geofencingEvent);
            }
        }
Exemplo n.º 16
0
// ---------------------------------------------------------------------------------------------------------------------------------- //

        public override void OnReceive(Context context, Intent intent)
        {
            bool entering = intent.GetBooleanExtra(LocationManager.KeyProximityEntering, false);

            GeofencingEvent geofencingEvent = GeofencingEvent.FromIntent(intent);

            if (geofencingEvent != null)
            {
                entering = geofencingEvent.GeofenceTransition == Geofence.GeofenceTransitionEnter;

                IList <IGeofence> crossedFences = geofencingEvent.TriggeringGeofences;

                Location location = geofencingEvent.TriggeringLocation;

                Log.Debug(GetType().Name,
                          string.Format("Entered at ({0},{1} and crossed {2} fence(s).",
                                        location.Latitude, location.Longitude, crossedFences.Count));
            }

            var extras = intent.GetBundleExtra(IntentName);

            string poiName = extras.GetString("name");

            int id = extras.GetInt("id");

            Tuple <Action <int>, Action <int> > work;

            actions.TryGetValue(id, out work);

            if (entering)
            {
                Log.Debug(GetType().Name, "Entering " + poiName + " - " + id);

                if (work != null && work.Item1 != null)
                {
                    work.Item1(id);
                }
            }
            else
            {
                Log.Debug(GetType().Name, "Exiting " + poiName + " - " + id);

                if (work != null && work.Item2 != null)
                {
                    work.Item2(id);
                }
            }
        }
Exemplo n.º 17
0
        public async Task Process(Intent intent)
        {
            var e = GeofencingEvent.FromIntent(intent);

            if (e == null)
            {
                return;
            }


            if (e.HasError)
            {
                Log.Write(
                    LocationLogCategory.Geofence,
                    "Event Error",
                    ("ErrorCode", GeofenceStatusCodes.GetStatusCodeString(e.ErrorCode))
                    );
            }
            else if (e.TriggeringGeofences != null)
            {
                foreach (var triggeringGeofence in e.TriggeringGeofences)
                {
                    var state  = (GeofenceState)e.GeofenceTransition;
                    var region = await this.repository.Get(triggeringGeofence.RequestId);

                    if (region == null)
                    {
                        Log.Write(
                            LocationLogCategory.Geofence,
                            "Not Found",
                            ("RequestId", triggeringGeofence.RequestId)
                            );
                    }
                    else
                    {
                        await this.delegates.RunDelegates(
                            x => x.OnStatusChanged(state, region),
                            ex => Log.Write(
                                ex,
                                ("RequestId", triggeringGeofence.RequestId),
                                ("Transition", state.ToString())
                                )
                            );
                    }
                }
            }
        }
        /// <summary>
        /// Handles incoming intents
        /// </summary>
        /// <param name="intent">The intent sent by Location Services. This Intent is provided to Location Services (inside a PendingIntent)
        /// when AddGeofences() is called</param>
        protected override void OnHandleIntent(Android.Content.Intent intent)
        {
            // First check for errors
            var geofencingEvent = GeofencingEvent.FromIntent(intent);

            if (geofencingEvent.HasError)
            {
                int errorCode = geofencingEvent.ErrorCode;
                Log.Error(Constants.TAG, "Location Services error: " + errorCode);
            }
            else
            {
                // Get the type of Geofence transition (i.e. enter or exit in this sample).
                int transitionType = geofencingEvent.GeofenceTransition;
                // Create a DataItem when a user enters one of the geofences. The wearable app will receie this and create a
                // notification to prompt him/her to check in
                if (transitionType == Geofence.GeofenceTransitionEnter)
                {
                    // Connect to the Google Api service in preparation for sending a DataItem
                    mGoogleApiClient.BlockingConnect(Constants.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 = geofencingEvent.TriggeringGeofences[0].RequestId;
                    // Create a DataItem with this geofence's id. The wearable can use this to create a notification
                    PutDataMapRequest putDataMapRequest = PutDataMapRequest.Create(Constants.GEOFENCE_DATA_ITEM_PATH);
                    putDataMapRequest.DataMap.PutString(Constants.KEY_GEOFENCE_ID, triggeredGeofenceId);
                    if (mGoogleApiClient.IsConnected)
                    {
                        WearableClass.DataApi.PutDataItem(
                            mGoogleApiClient, putDataMapRequest.AsPutDataRequest()).Await();
                    }
                    else
                    {
                        Log.Error(Constants.TAG, "Failed to send data item: " + putDataMapRequest +
                                  " - disconnected from Google Play Services");
                    }
                    mGoogleApiClient.Disconnect();
                }
                else if (Geofence.GeofenceTransitionExit == transitionType)
                {
                    // Delete the data item when leaving a geofence region
                    mGoogleApiClient.BlockingConnect(Constants.CONNECTION_TIME_OUT_MS, TimeUnit.Milliseconds);
                    WearableClass.DataApi.DeleteDataItems(mGoogleApiClient, Constants.GEOFENCE_DATA_ITEM_URI).Await();
                    mGoogleApiClient.Disconnect();
                }
            }
        }
Exemplo n.º 19
0
        protected override void OnHandleIntent(Intent intent)
        {
            var gEvent = GeofencingEvent.FromIntent(intent);

            if (gEvent.GeofenceTransition == Geofence.GeofenceTransitionEnter)
            {
                foreach (var geofence in gEvent.TriggeringGeofences)
                {
                    var location = LocationDB.GetLocation(int.Parse(geofence.RequestId));
                    if (location.Active)
                    {
                        CrossLocalNotifications.Current.Show(location.Title, location.Description);
                        CrossVibrate.Current.Vibration();
                    }
                }
            }
        }
Exemplo n.º 20
0
        public override void OnReceive(Context context, Intent intent)
        {
            var geofencingEvent    = GeofencingEvent.FromIntent(intent);
            var geofenceTransition = geofencingEvent.GeofenceTransition;
            var message            = "";

            switch (geofenceTransition)
            {
            case Geofence.GeofenceTransitionEnter:
                message = intent.GetStringExtra(Constans.EntryMessage);
                break;

            case Geofence.GeofenceTransitionExit:
                message = intent.GetStringExtra(Constans.ExitMessage);
                break;
            }

            CreateNotificationChannel(context);
            SendNotificationToChannel(CHANNEL_ID, CHANNEL_NAME, Resource.Mipmap.ic_launcher,
                                      message, context, NotificationCompat.PriorityDefault, true);
        }
        protected override void OnHandleIntent(Intent intent)
        {
            var geofencingEvent = GeofencingEvent.FromIntent(intent);

            if (geofencingEvent.HasError)
            {
                Log.Error(TAG, geofencingEvent.ErrorCode.ToString());
                return;
            }

            int geofenceTransition = geofencingEvent.GeofenceTransition;

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

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

                //SendNotification(geofenceTransitionDetails);

                Intent geofenceIntent = new Intent();
                geofenceIntent.SetAction("uk.co.eastpoint.GeofenceBroadcast");
                geofenceIntent.PutExtra("GetGeofenceTransitionDetails", geofenceTransitionDetails);
                if (geofenceTransition == Geofence.GeofenceTransitionExit)
                {
                    string exitedIntersection = GetGeofenceIntersectionExited(this, triggeringGeofences);
                    geofenceIntent.PutExtra("GetGeofenceIntersectionExited", exitedIntersection);
                }

                SendBroadcast(geofenceIntent);

                Log.Info(TAG, geofenceTransitionDetails);
            }
            else
            {
                // Log the error.
                Log.Error(TAG, "transition invalid", new[] { new Java.Lang.Integer(geofenceTransition) });
            }
        }
Exemplo n.º 22
0
        public override void OnReceive(Context context, Intent intent)
        {
            GeofencingEvent geofencingEvent = GeofencingEvent.FromIntent(intent);

            if (geofencingEvent.HasError)
            {
                string error = GeofenceStatusCodes.GetStatusCodeString(geofencingEvent.ErrorCode);
                Console.WriteLine($"Error Code: {geofencingEvent.ErrorCode}. Error: {error}");
                return;
            }

            // Get the transition type.
            int geofenceTransition = geofencingEvent.GeofenceTransition;
            // Get the geofences that were triggered. A single event can trigger
            // multiple geofences.
            IList <IGeofence>    triggeringGeofences  = geofencingEvent.TriggeringGeofences;
            NotificationsService notificationsService = new NotificationsService(context);

            switch (geofenceTransition)
            {
            case Geofence.GeofenceTransitionEnter:
                notificationsService.SendNotification("¡Entraste!", "¡Te hemos pillado cerca!", 10000);
                break;

            case Geofence.GeofenceTransitionExit:
                notificationsService.SendNotification("¡Saliste!", "¡Te hemos pillado saliendo!", 10000);
                break;

            case Geofence.GeofenceTransitionDwell:
                notificationsService.SendNotification("¡Te quedas!", "¿¡No te mueves!?", 10000);
                break;

            default:
                // Log the error.
                Console.WriteLine("Broadcast not implemented.");
                break;
            }
        }
Exemplo n.º 23
0
        protected override void OnHandleIntent(Intent intent)
        {
            var ge = GeofencingEvent.FromIntent(intent);

            var transition = ge.GeofenceTransition;

            if (transition == Geofence.GeofenceTransitionExit)
            {
                var builder = new NotificationCompat.Builder(this);
                builder.SetSmallIcon(Resource.Mipmap.Icon)
                .SetColor(Color.Red)
                .SetContentTitle("Location changed")
                .SetContentText($"Test {foo++}")
                .SetPriority(NotificationCompat.PriorityMax);

                builder.SetAutoCancel(true);

                var mNotificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
                mNotificationManager?.Notify(0, builder.Build());

                SetGeofence();
            }
        }
Exemplo n.º 24
0
        protected void HandleGeofencingEvent(GeofencingEvent geoEvent)
        {
            Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::Received Geofence event: {0}", geoEvent.GeofenceTransition));
            Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::Num Geofences event: {0}", geoEvent.TriggeringGeofences.Count));

            // find the region
            TrackedRegion trackedRegion = Regions.Where(gf => gf.Region.RequestId == geoEvent.TriggeringGeofences[0].RequestId).Single( );

            if (trackedRegion != null)
            {
                Rock.Mobile.Util.Debug.WriteToLog(string.Format("Starting timer for region {0}", trackedRegion.Region.RequestId));

                // don't process this geoevent NOW. instead, queue it, and we'll wait 10 seconds.
                // that way, if it's a false positive (like a quit exit-enter) we won't process it.
                trackedRegion.GeofenceEventTimer.Stop( );
                trackedRegion.PendingGeofenceEvent = geoEvent;
                trackedRegion.GeofenceEventTimer.Start( );
            }
            else
            {
                Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::Received geofence event for unknown region: {0}", geoEvent.TriggeringGeofences[0].RequestId));
            }
        }
Exemplo n.º 25
0
        protected override void OnHandleIntent(Intent intent)
        {
            GeofencingEvent geofencingEvent = GeofencingEvent.FromIntent(intent);

            if (geofencingEvent.HasError)
            {
                int err = geofencingEvent.ErrorCode;
                //TODO: get this error code
                Console.WriteLine($"Error: {err}");
                return;
            }

            //Get Transition Type
            int geofenceTransition = geofencingEvent.GeofenceTransition;

            //Test the transition

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

                foreach (var transition in triggeringGeofences)
                {
                    Console.WriteLine(transition.RequestId, geofenceTransition);
                }

                Console.WriteLine("ENTERED ENTERED ENTERED ENTERED ENTERED ENTERED!!!!");

                //TODO: send notification here?
            }
            else
            {
                Console.WriteLine(geofenceTransition.GetTypeCode());
            }
        }
Exemplo n.º 26
0
 protected override void OnHandleIntent(Intent intent)
 {
     Log.Debug("geofence", "hereeeeeeeeeeeeeee");
     var geofencingEvent = GeofencingEvent.FromIntent(intent);
 }
Exemplo n.º 27
0
        internal void HandlePendingGeofencingEvent(GeofencingEvent geoEvent, TrackedRegion trackedRegion)
        {
            Rock.Mobile.Util.Debug.WriteToLog(string.Format("Handling event for region {0}", trackedRegion.Region.RequestId));

            // if we're entering, turn on intense scanning
            if (geoEvent.GeofenceTransition == Geofence.GeofenceTransitionEnter)
            {
                // make sure we're not IN the region yet (we could be if this is the result of a false positive,
                // like, we're in a region, and suddently get an 'exit-entered')
                if (trackedRegion.InRegion == false)
                {
                    trackedRegion.InRegion = true;

                    // start intense scanning right away
                    StartIntenseLocationScanning( );

                    // notify the handler if they're interested and there is one
                    SendLocationUpdateIntent(LocationEvent_EnteredRegion, trackedRegion.Region.RequestId, "");
                }
                else
                {
                    Rock.Mobile.Util.Debug.WriteToLog(string.Format("Ignoring ENTER for region {0} because we're already in it.", trackedRegion.Region.RequestId));
                }
            }
            // else we're leaving...
            else
            {
                // make sure we're not OUT of the region yet (we could be if this is the result of a false positive,
                // like, we're outside a region, and suddently get an 'entered-exit')
                if (trackedRegion.InRegion == true)
                {
                    trackedRegion.InRegion = false;

                    // if this region owned our current landmark, reset that as well.
                    if (trackedRegion.LandmarkInRegion(CurrentLandmark))
                    {
                        CurrentLandmark = null;
                    }


                    // and turn off intensive scanning IF we're not in anymore regions at all
                    bool outsideAllRegions = true;

                    foreach (TrackedRegion region in Regions)
                    {
                        // if we find at least one region still being tracked, don't stop scanning.
                        if (region.InRegion == true)
                        {
                            outsideAllRegions = false;
                            break;
                        }
                    }

                    if (outsideAllRegions)
                    {
                        Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::OUTSIDE ALL REGIONS. STOPPING INTENSE SCANNING"));
                        StopIntenseLocationScanning( );
                    }

                    // notify the handler if they're interested and there is one
                    SendLocationUpdateIntent(LocationEvent_ExitedRegion, trackedRegion.Region.RequestId, outsideAllRegions.ToString( ));
                }
                else
                {
                    Rock.Mobile.Util.Debug.WriteToLog(string.Format("Ignoring EXIT for region {0} because we're already in it.", trackedRegion.Region.RequestId));
                }
            }
        }