private async void OnClickRequestActivityTransitionUpdate(object sender, EventArgs eventArgs) { string Tag = "RequestActivityTransitionUpdate"; long detectionIntervalMillis = 5000; pendingIntent = GetPendingIntent(); LocationBroadcastReceiver.AddIdentificationListener(); var task = activityIdentificationService.CreateActivityIdentificationUpdatesAsync(detectionIntervalMillis, pendingIntent); try { await task; if (task.IsCompleted) { log.Info(Tag, $"CreateActivityIdentificationUpdates succeeded."); } else { log.Error(Tag, $"CreateActivityIdentificationUpdates failed: {task.Exception.Message}"); } } catch (Exception e) { if (e is ApiException apiException) { if (apiException.StatusCode == 10803) { //PermissionDenied Utils.RequestActivityTransitionPermission(this); } } log.Error(Tag, $"CreateActivityIdentificationUpdates exception: {e.Message}"); } }
public void Initalize() { Log.Info("MainActivity", "Google Play Services is installed on this device."); apiClient = new GoogleApiClient.Builder(this, this, this) .AddApi(LocationServices.API).Build(); // generate a location request that we will pass into a call for location updates locRequest = new LocationRequest(); locRequest.SetPriority(100); // Setting interval between updates, in milliseconds // NOTE: the default FastestInterval is 1 minute. If you want to receive location updates more than // once a minute, you _must_ also change the FastestInterval to be less than or equal to your Interval locRequest.SetFastestInterval(500); locRequest.SetInterval(1000); // setting up the time sendUpdateTimer = new System.Timers.Timer(AppConfig.PostInterval * 1000); sendUpdateTimer.AutoReset = false; sendUpdateTimer.Elapsed += (sender, e) => onPostInterval(sender, e); // Map of sensor details sensorDetailMap = new Dictionary <string, SensorDetail>(); // Broadcast re receiver = new SensorReadingBroadcastReceiver(); receiver.OnSensorReading += (sender, e) => onNewSensor(sender, e); // location rec locationReceiver = new LocationBroadcastReceiver(); }
public LocationService_Droid() { _service = _service ?? new LocationService(); if (_receiver == null) { _receiver = new LocationBroadcastReceiver(); MainActivity.Instance.RegisterReceiver(_receiver, new Android.Content.IntentFilter(Constants.Action.LOCATION_CHANGED)); } }
private async void OnClickRemoveActivityTransitionUpdate(object sender, EventArgs eventArgs) { string Tag = "RemoveActivityTransitionUpdate"; LocationBroadcastReceiver.RemoveIdentificationListener(); var task = activityIdentificationService.DeleteActivityIdentificationUpdatesAsync(pendingIntent); try { await task; if (task.IsCompleted) { log.Info(Tag, $"DeleteActivityIdentificationUpdates succeeded."); } else { log.Error(Tag, $"DeleteActivityIdentificationUpdates failed: {task.Exception.Message}"); } } catch (Exception e) { log.Error(Tag, $"DeleteActivityIdentificationUpdates exception: {e.Message}"); } }