protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // get your app ID and token on:
            // https://cloud.estimote.com/#/apps/add/your-own-app
            var creds = new EstimoteCloudCredentials("app ID", "app token");

            // starting with Android 8.0, the most reliable way to keep
            // Bluetooth scanning active when the user leaves the app is through
            // a foreground service, and for that to work we're required to show
            // a notification that informs the user about the activity
            //
            // read more about it on:
            // https://developer.android.com/guide/components/services.html#Foreground

            var channelId = "proximity_scanning";

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                // Android 8.0 and up require a channel for the notifications
                var channel             = new NotificationChannel(channelId, "Bluetooth activity", NotificationImportance.Low);
                var notificationManager = this.GetSystemService(Context.NotificationService) as NotificationManager;
                notificationManager.CreateNotificationChannel(channel);
            }
            var notification = new NotificationCompat.Builder(this, channelId)
                               .SetSmallIcon(global::Android.Resource.Drawable.IcDialogInfo)
                               .SetContentTitle("Proximity")
                               .SetContentText("Proximity demo is scanning for beacons")
                               .Build();

            observer = new ProximityObserverBuilder(ApplicationContext, creds)
                       .WithBalancedPowerMode()

                       // see the longer comment above about the foreground service and
                       // the notification
                       //
                       // if you only intend to use beacons while the app is open, you
                       // can safely remove this line
                       .WithScannerInForegroundService(notification)

                       .OnError(new MyErrorHandler())
                       .Build();

            zone = new ProximityZoneBuilder()
                   .ForTag("lobby")
                   .InCustomRange(20.0)
                   .OnEnter(new MyEnterHandler())
                   .Build();

            // the actual observation starts further below in OnResume or
            // OnRequestPermissionsResult, once we obtain the location
            // permission from the user, or confirm that we already have it

            Log.Debug("app", "Proximity all ready to go!");
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // get your app ID and token on:
            // https://cloud.estimote.com/#/apps/add/your-own-app
            var creds = new EstimoteCloudCredentials("app ID", "app token");

            // starting with Android 8.0, the most reliable way to keep
            // Bluetooth scanning active is through a foreground service, and
            // for that to work we're required to show a notification that
            // informs the user about the activity
            //
            // read more about it on:
            // https://developer.android.com/guide/components/services.html#Foreground

            var channelId = "proximity_scanning";

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                // Android 8.0 and up require a channel for the notifications
                var channel             = new NotificationChannel(channelId, "Bluetooth activity", NotificationImportance.Low);
                var notificationManager = this.GetSystemService(Context.NotificationService) as NotificationManager;
                notificationManager.CreateNotificationChannel(channel);
            }
            notification = new NotificationCompat.Builder(this, channelId)
                           .SetSmallIcon(Resource.Drawable.notification_icon_background)
                           .SetContentTitle("Proximity")
                           .SetContentText("Proximity demo is scanning for beacons")
                           .Build();

            observer = new ProximityObserverBuilder(ApplicationContext, creds)
                       .WithBalancedPowerMode()
                       .WithTelemetryReporting()
                       .WithScannerInForegroundService(notification)
                       .WithOnErrorAction(new MyErrorHandler())
                       .Build();

            var zone1 = observer
                        .ZoneBuilder()
                        .ForAttachmentKeyAndValue("beacon", "beetroot")
                        .InNearRange()
                        .WithOnEnterAction(new MyEnterHandler())
                        .Create();

            observer.AddProximityZone(zone1);

            // the actual observation starts further below in OnResume or
            // OnRequestPermissionsResult, once we obtain the location
            // permission from the user, or confirm that we already have it

            Log.Debug("app", "Proximity all ready to go!");
        }
        private void CreateObserver(Android.Content.Context context)
        {
            var creds = new EstimoteCloudCredentials(Helpers.Settings.AppIdEstimote, Helpers.Settings.AppTokenEstimote);

            Observer = new ProximityObserverBuilder(context, creds)
                       .WithAnalyticsReportingDisabled()
                       .WithBalancedPowerMode()
                       .WithScannerInForegroundService(notification)
                       .WithOnErrorAction(new ObservingErrorHandler())
                       .Build();
        }
Exemple #4
0
        void StartLocationUpdates()
        {
            if (locationUpdatesStarted)
            {
                return;
            }
            else
            {
                locationUpdatesStarted = true;
            }

            if (indoorManager != null)
            {
                Log.Debug("app", "indoorManager already initialized, starting position updates");

                indoorManager.StartPositioning();

                return;
            }

            // starting with Android 8.0, the most reliable way to keep
            // Bluetooth scanning active when the user leaves the app is through
            // a foreground service, and for that to work we're required to show
            // a notification that informs the user about the activity
            //
            // read more about it on:
            // https://developer.android.com/guide/components/services.html#Foreground

            var channelId = "indoor_location";

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                // Android 8.0 and up require a channel for the notifications
                var channel             = new NotificationChannel(channelId, "Bluetooth activity", NotificationImportance.Low);
                var notificationManager = this.GetSystemService(Context.NotificationService) as NotificationManager;
                notificationManager.CreateNotificationChannel(channel);
            }
            var notification = new NotificationCompat.Builder(this, channelId)
                               .SetSmallIcon(global::Android.Resource.Drawable.IcDialogInfo)
                               .SetContentTitle("Indoor Location")
                               .SetContentText("Indoor Location updates are running")
                               .Build();

            var creds = new EstimoteCloudCredentials(APP_ID, APP_TOKEN);

            var getLocationHandler = new GetLocationHandler();

            getLocationHandler.GetLocationSuccess += (location) =>
            {
                Log.Debug("app", $"Successfully fetched location from Estimote Cloud: {location}");
                Log.Debug("app", "Initializing indoorManager and starting position updates");

                locationView.SetLocation(location);

                indoorManager = new IndoorLocationManagerBuilder(this, location, creds)

                                // see the longer comment above about the foreground service and
                                // the notification
                                //
                                // if you only intend to use beacons while the app is open, you
                                // can safely remove this line
                                .WithScannerInForegroundService(notification)

                                .Build();

                indoorManager.SetOnPositionUpdateListener(new PositionUpdateHandler(locationView));
                indoorManager.StartPositioning();
            };
            getLocationHandler.GetLocationFailure += (error) =>
            {
                Log.Error("app", $"Failed to fetch the location from Estimote Cloud: {error}");
            };

            Log.Debug("app", $"Fetching location '{LOCATION_ID}' from Estimote Cloud...");
            new IndoorCloudManagerFactory()
            .Create(this, creds)
            .GetLocation(LOCATION_ID, getLocationHandler);
        }