コード例 #1
0
        public async void StartRagingBeacons()
        {
            await Task.Run(() =>
            {
                _beaconManager = BeaconManager.GetInstanceForApplication(this);
                _rangeNotifier = new RangeNotifier();

                _connection = DependencyService.Get <ISQLiteConnectionProvider>().GetConnection();
                _connection.CreateTable <BeaconDataModel>();

                //iBeacon
                _beaconManager.BeaconParsers.Add(new BeaconParser().SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
                _beaconManager.Bind(this);

                _rangeNotifier.DidRangeBeaconsInRegionComplete += DidRangeBeaconsInRegionComplete;
                _beaconManager.AddRangeNotifier(_rangeNotifier);

                _rangingRegion = new Region(AppConstants.AppName, Identifier.Parse(AppConstants.iBeaconAppUuid), null, null);

                try
                {
                    _beaconManager.StartRangingBeaconsInRegion(_rangingRegion);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("StartRangingException: " + ex.Message);
                }
            });
        }
        public void DidEnterRegion(AltBeaconOrg.BoundBeacon.Region region)
        {
            // In this example, this class sends a notification to the user whenever a Beacon
            // matching a Region (defined above) are first seen.
            Log.Debug(TAG, "did enter region.");
            if (!haveDetectedBeaconsSinceBoot)
            {
                Log.Debug(TAG, "auto launching MonitoringActivity");

                // The very first time since boot that we detect an beacon, we launch the
                // MainActivity
                var intent = new Intent(this, typeof(MainActivity));
                intent.SetFlags(ActivityFlags.NewTask);
                // Important:  make sure to add android:launchMode="singleInstance" in the manifest
                // to keep multiple copies of this activity from getting created if the user has
                // already manually launched the app.
                this.StartActivity(intent);
                haveDetectedBeaconsSinceBoot = true;
            }
            else
            {
                if (mainActivity != null)
                {
                    Log.Debug(TAG, "I see a beacon again");
                }
                else
                {
                    // If we have already seen beacons before, but the monitoring activity is not in
                    // the foreground, we send a notification to the user on subsequent detections.
                    Log.Debug(TAG, "Sending notification.");
                    SendNotification();
                }
            }
        }
コード例 #3
0
        public void StartMonitoring(string uuid, double major, double minor, string identifier)
        {
            if (IsMonitoringBeacons)
            {
                return;
            }

            // save region details
            this.uuid       = uuid;
            this.major      = major;
            this.minor      = minor;
            this.identifier = identifier;

            // initiate service
            if (!isBinded)
            {
                InitializeService();
            }

            if (!isServiceBound)
            {
                // service not bound.
                // this happened because we just started the service. Wait for OnBeaconServiceConnect event on MainActivity
                isStartMonitoringRequested = true;
                return;
            }

            // check bluetooh
            CheckBluetoothEnabled();

            // start monitoring
            if (major == 0 && minor == 0)
            {
                _tagRegion = new Region(identifier, Identifier.Parse(uuid), null, null);
            }
            else
            {
                _tagRegion = new Region(identifier, Identifier.Parse(uuid), Identifier.FromInt((int)major),
                                        Identifier.FromInt((int)minor));
            }

            BeaconManagerImpl.ForegroundBetweenScanPeriod = 1000;

            BeaconManagerImpl.AddMonitorNotifier(_monitorNotifier);
            _beaconManager.StartMonitoringBeaconsInRegion(_tagRegion);

            _beaconManager.StartMonitoringBeaconsInRegion(_tagRegion);

            BeaconManagerImpl.AddRangeNotifier(_rangeNotifier);
            _beaconManager.StartRangingBeaconsInRegion(_tagRegion);

            IsMonitoringBeacons = true;

            Log.Debug("FLBEACON", "StartMonitoring");

            logService.WriteToLog(LOG_FILENAME, "StartMonitoring");
        }
コード例 #4
0
        public virtual void DidEnterRegion(AltBeaconOrg.BoundBeacon.Region region)
        {
            MvxTrace.TaggedTrace(TAG, "DidEnterRegion {1}. SinceBoot: {0}", _haveDetectedBeaconsSinceBoot, region.UniqueId);

            if (!_haveDetectedBeaconsSinceBoot)
            {
                _haveDetectedBeaconsSinceBoot = true;
            }
        }
コード例 #5
0
        void IBeaconConsumer.OnBeaconServiceConnect()
        {
            _beaconManager.SetForegroundBetweenScanPeriod(1000);

            _beaconManager.SetRangeNotifier(_rangeNotifier);

            //_tagRegion = new AltBeaconOrg.BoundBeacon.Region("Id", Identifier.Parse("EBEFD083-70A2-47C8-9837-E7B5634DF524"), null, null);
            _emptyRegion = new AltBeaconOrg.BoundBeacon.Region("Id", null, null, null);

            //_beaconManager.StartRangingBeaconsInRegion(_tagRegion);
            _beaconManager.StartRangingBeaconsInRegion(_emptyRegion);
        }
コード例 #6
0
        private BeaconManager InitializeBeaconManager()
        {
            RequestPermission();
            // Enable the BeaconManager
            _beaconManager = BeaconManager.GetInstanceForApplication(_mainActivity);

            /*
             #region Set up Beacon Simulator for TEST USE
             * // Beacon Simulator
             * var beaconSimulator = new BeaconSimulator();
             * beaconSimulator.CreateBasicSimulatedBeacons();
             * BeaconManager.BeaconSimulator = beaconSimulator;
             * // Beacon Simulator
             #endregion Set up Beacon Simulator for TEST USE
             */

            _monitorNotifier = new MonitorNotifier();
            _rangeNotifier   = new RangeNotifier();

            //iBeacon
            BeaconParser beaconParser = new BeaconParser().SetBeaconLayout(AppConstants.iBeaconFormat);

            _beaconManager.BeaconParsers.Add(beaconParser);

            // BeaconManager Setting
            // Check Touch おそらくmain activity beacon consumer側で設定

            /*
             * _beaconManager.SetForegroundScanPeriod(AppConstants.BEACONS_UPDATES_IN_MILLISECONDS);
             * _beaconManager.SetForegroundBetweenScanPeriod(AppConstants.BEACONS_UPDATES_IN_MILLISECONDS);
             * _beaconManager.SetBackgroundScanPeriod(AppConstants.BEACONS_UPDATES_IN_MILLISECONDS);
             * _beaconManager.SetBackgroundBetweenScanPeriod(AppConstants.BEACONS_UPDATES_IN_MILLISECONDS);
             * _beaconManager.UpdateScanPeriods();
             */

            // MonitorNotifier
            _monitorNotifier.DetermineStateForRegionComplete += DetermineStateForRegionComplete;
            _monitorNotifier.EnterRegionComplete             += EnterRegionComplete;
            _monitorNotifier.ExitRegionComplete += ExitRegionComplete;
            _beaconManager.AddMonitorNotifier(_monitorNotifier);

            // RangeNotifier
            _rangeNotifier.DidRangeBeaconsInRegionComplete += DidRangeBeaconsInRegionComplete;
            _beaconManager.AddRangeNotifier(_rangeNotifier);


            _fieldRegion = new AltBeaconOrg.BoundBeacon.Region("AppAppApp", Identifier.Parse(AppConstants.iBeaconAppUuid), null, null);

            _beaconManager.Bind(_mainActivity);
            return(_beaconManager);
        }
コード例 #7
0
        public void OnBeaconServiceConnect()
        {
            _beaconManager.SetForegroundBetweenScanPeriod(5000);             // 5000 milliseconds

            _beaconManager.SetRangeNotifier(_rangeNotifier);

            _tagRegion   = new AltBeaconOrg.BoundBeacon.Region("myUniqueBeaconId", Identifier.Parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"), null, null);
            _emptyRegion = new AltBeaconOrg.BoundBeacon.Region("myEmptyBeaconId", null, null, null);

            _beaconManager.StartRangingBeaconsInRegion(_tagRegion);
            _beaconManager.StartRangingBeaconsInRegion(_emptyRegion);

            _startButton.Enabled = false;
        }
コード例 #8
0
        public virtual void OnBeaconServiceConnect()
        {
            _beaconManager.SetForegroundScanPeriod(BEACONS_UPDATES_IN_MILLISECONDS);
            _beaconManager.SetForegroundBetweenScanPeriod(BEACONS_UPDATES_IN_MILLISECONDS);

            _beaconManager.SetBackgroundScanPeriod(BEACONS_UPDATES_IN_MILLISECONDS);
            _beaconManager.SetBackgroundBetweenScanPeriod(BEACONS_UPDATES_IN_MILLISECONDS);

            _beaconManager.UpdateScanPeriods();

            _rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;
            _beaconManager.SetRangeNotifier(_rangeNotifier);

            _rangingRegion = new AltBeaconOrg.BoundBeacon.Region(BEACONS_REGION_HEADER, null, null, null);
            _beaconManager.StartRangingBeaconsInRegion(_rangingRegion);
        }
コード例 #9
0
        private BeaconManager InitializeBeaconManager()
        {
            // Enable the BeaconManager
            _beaconManager = BeaconManager.GetInstanceForApplication(_mainActivity);

            #region Set up Beacon Simulator for TEST USE
            // Beacon Simulator
            var beaconSimulator = new BeaconSimulator();
            beaconSimulator.CreateBasicSimulatedBeacons();
            BeaconManager.BeaconSimulator = beaconSimulator;
            // Beacon Simulator
            #endregion Set up Beacon Simulator for TEST USE

            _monitorNotifier        = new MonitorNotifier();
            _rangeNotifier          = new RangeNotifier();
            _dictionaryOfBeaconData = new Dictionary <string, BeaconDataModel>();

            //iBeacon
            BeaconParser beaconParser = new BeaconParser().SetBeaconLayout(AppConstants.IBEACON_FORMAT);
            _beaconManager.BeaconParsers.Add(beaconParser);


            // BeaconManager Setting

            /*
             * _beaconManager.SetForegroundScanPeriod(AppConstants.BEACONS_UPDATES_IN_MILLISECONDS);
             * _beaconManager.SetForegroundBetweenScanPeriod(AppConstants.BEACONS_UPDATES_IN_MILLISECONDS);
             * _beaconManager.SetBackgroundScanPeriod(AppConstants.BEACONS_UPDATES_IN_MILLISECONDS);
             * _beaconManager.SetBackgroundBetweenScanPeriod(AppConstants.BEACONS_UPDATES_IN_MILLISECONDS);
             * _beaconManager.UpdateScanPeriods();
             */

            // MonitorNotifier
            _monitorNotifier.DetermineStateForRegionComplete += DetermineStateForRegionComplete;
            _monitorNotifier.EnterRegionComplete             += EnterRegionComplete;
            _monitorNotifier.ExitRegionComplete += ExitRegionComplete;
            _beaconManager.AddMonitorNotifier(_monitorNotifier);

            // RangeNotifier
            _rangeNotifier.DidRangeBeaconsInRegionComplete += DidRangeBeaconsInRegionComplete;
            _beaconManager.AddRangeNotifier(_rangeNotifier);


            _fieldRegion = new AltBeaconOrg.BoundBeacon.Region(AppConstants.AppUUID, null, null, null);
            _beaconManager.Bind(_mainActivity);
            return(_beaconManager);
        }
コード例 #10
0
        private BeaconManager InitializeBeaconManager()
        {
            // Enable the BeaconManager
            BeaconManager bm = BeaconManager.GetInstanceForApplication(Xamarin.Essentials.Platform.CurrentActivity);

            var iBeaconParser = new BeaconParser();

            // EDDYSTONE TLM  x,s: 0 - 1 = feaa,m: 2 - 2 = 20,d: 3 - 3,d: 4 - 5,d: 6 - 7,d: 8 - 11,d: 12 - 15
            // EDDYSTONE UID  s: 0 - 1 = feaa,m: 2 - 2 = 00,p: 3 - 3:-41,i: 4 - 13,i: 14 - 19
            // EDDYSTONE URL  s: 0 - 1 = feaa,m: 2 - 2 = 10,p: 3 - 3:-41,i: 4 - 20v
            // IBEACON        m: 2 - 3 = 0215,i: 4 - 19,i: 20 - 21,i: 22 - 23,p: 24 - 24
            iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
            bm.BeaconParsers.Add(iBeaconParser);

            rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;

            //tagRegion = new AltBeaconOrg.BoundBeacon.Region("Beacon 1", Identifier.Parse("8E6DBFBB-489D-418A-9560-1BA1CE6301AA"), null, null);
            tagRegion = new AltBeaconOrg.BoundBeacon.Region("EmptyBeaconId", null, null, null);

            bm.BackgroundMode = false;
            bm.Bind((IBeaconConsumer)Xamarin.Essentials.Platform.CurrentActivity);

            return(bm);
        }
 public void DidExitRegion(AltBeaconOrg.BoundBeacon.Region region)
 {
     Log.Debug(TAG, "did exit region.");
 }
 public void DidDetermineStateForRegion(int state, AltBeaconOrg.BoundBeacon.Region region)
 {
 }
コード例 #13
0
ファイル: RangeNotifier.cs プロジェクト: wmmihaa/Covid19Radar
 public void DidRangeBeaconsInRegion(ICollection <Beacon> beacons, AltBeaconOrg.BoundBeacon.Region region)
 {
     DidRangeBeaconsInRegionComplete?.Invoke(this, beacons);
 }
コード例 #14
0
 public virtual void DidExitRegion(AltBeaconOrg.BoundBeacon.Region region)
 {
     MvxTrace.TaggedTrace(TAG, "DidExitRegion");
 }
コード例 #15
0
 public virtual void DidDetermineStateForRegion(int state, AltBeaconOrg.BoundBeacon.Region region)
 {
     MvxTrace.TaggedTrace(TAG, "DidDetermineStateForRegion {2}. State: {0}, SinceBoot: {1}", state, _haveDetectedBeaconsSinceBoot, region.UniqueId);
 }