Beispiel #1
0
        public override void OnDestroy()
        {
            base.OnDestroy();

            ILocationServiceApi.Disconnect( );
            Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::OnDestroy"));
        }
Beispiel #2
0
        public void CommitRegionsForTrack( )
        {
            // if we're connected to google services, update our regions.
            if (ILocationServiceApi.IsConnected)
            {
                Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::CommitRegionsForTrack - GooglePlay connected. Comitting regions."));

                // make sure the user called 'BeginAddRegionsForTrack'
                if (CommitState == RegionCommitState.QueuingRegions)
                {
                    // request their removal NOW (why not, might allow them to be done by the time the new ones are added)
                    if (PendingRegionsForRemove.Count > 0)
                    {
                        Android.Gms.Common.Apis.IPendingResult iRemovePendingResult = LocationServices.GeofencingApi.RemoveGeofences(ILocationServiceApi, PendingRegionsForRemove);
                        iRemovePendingResult.SetResultCallback(this);

                        CommitState = RegionCommitState.Removing;
                    }
                    else
                    {
                        InternalCommitRegionsForTrack( );
                    }
                }
            }
            else
            {
                Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::CommitRegionsForTrack - GooglePlay NOT CONNECTED. Queuing region commit, and connecting to GooglePlay."));

                // otherwise, flag that we want to commit, and connect the service.
                PendingRegionCommitEvent = true;
                ILocationServiceApi.Connect( );
            }
        }
Beispiel #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);
        }
Beispiel #4
0
        public override void OnCreate()
        {
            base.OnCreate();

            Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::OnCreate"));

            GoogleServicesFirstConnectionComplete = false;
            PendingRegionCommitEvent = false;

            IntenseScanningEnabled = false;

            Binder = new LocationManagerBinder(this);

            // Build our interface to the google play location services.
            Android.Gms.Common.Apis.GoogleApiClientBuilder apiBuilder = new Android.Gms.Common.Apis.GoogleApiClientBuilder(this, this, this);
            apiBuilder.AddApi(LocationServices.Api);
            apiBuilder.AddConnectionCallbacks(this);
            apiBuilder.AddOnConnectionFailedListener(this);

            ILocationServiceApi = apiBuilder.Build( );
            //

            // establish a connection
            ILocationServiceApi.Connect( );

            // setup our regions
            Regions = new List <TrackedRegion>( );
        }