/** * 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); }
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); } }
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) })); } }
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); }
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); }
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) })); } }
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); } } } }
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) { 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(); } } }
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)); } }
// 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) })); } }
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); } }
// ---------------------------------------------------------------------------------------------------------------------------------- // 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); } } }
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(); } } }
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(); } } } }
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) }); } }
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; } }
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(); } }
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()); } }
protected override void OnHandleIntent(Intent intent) { Log.Debug("geofence", "hereeeeeeeeeeeeeee"); var geofencingEvent = GeofencingEvent.FromIntent(intent); }