示例#1
0
        /// <summary>
        /// ジオフェンス登録完了処理
        /// </summary>
        /// <param name="task"></param>
        public void OnComplete(Task task)
        {
            string message;
            bool   successful;
            var    adapter = new DependencyServices.DbAdapter_Droid();

            if (task.IsSuccessful)
            {
                message    = _context.GetString(Resource.String.complete_add_geofence);
                successful = true;
                System.Diagnostics.Debug.WriteLine(message);
                GeofenceAdded = true;
            }
            else
            {
                // Get the status code for the error and log it using a user-friendly message.
                message    = GeofenceErrorMessages.GetErrorString(_context, task.Exception);
                successful = false;
                System.Diagnostics.Debug.WriteLine(message);
                GeofenceAdded = false;
            }

            adapter.AddDeviceLog("ジオフェンス登録処理", message);

            if (CompleteListener != null)
            {
                CompleteListener.RegisterCompleted(successful, message);
            }
        }
        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) }));
            }
        }