protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SystemRequirementsChecker.CheckWithDefaultDialogs(this); Estimote.EnableDebugLogging(true); Estimote.Initialize(this, "test-nm6", "9e7bddbce8bbbfc9d6427ece93bf279d"); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.myButton); button.Click += delegate { button.Text = $"{count++} clicks!"; }; // Create your application here beaconManager = new BeaconManager(this); beaconManager.Nearable += (sender, e) => { var items = e.Nearables; if (items.Count > 0) { Toast.MakeText(this, string.Format("Found {0} nearables.", items.Count), ToastLength.Short).Show(); } }; beaconManager.Connect(this); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); progressBar = FindViewById <ProgressBar> (Resource.Id.progressBar); noBeacons = FindViewById <TextView> (Resource.Id.no_beacons); ListAdapter = new BeaconAdapter(this); //create a new beacon manager to handle starting and stopping ranging beaconManager = new BeaconManager(this); //manually check for BLE var ble = Android.Content.PM.PackageManager.FeatureBluetoothLe; if (PackageManager.HasSystemFeature(ble)) { Toast.MakeText(this, "BLE not supported", ToastLength.Short).Show(); } //Validation checks if (!beaconManager.HasBluetooth) { //no bluetooth :( DisplayMessage("No bluetooth on your device.", ":("); beaconsEnabled = false; } else if (!beaconManager.IsBluetoothEnabled) { //bluetooth is not enabled DisplayMessage("Please turn on bluetooth.", ":("); beaconsEnabled = false; } else if (!beaconManager.CheckPermissionsAndService()) { //issues with permissions and service DisplayMessage("Issues with service and persmissions.", ":("); beaconsEnabled = false; } //major and minor are optional, pass in null if you don't need them beaconRegion = new Region(beaconId, uuid, null, null); //Event for when ranging happens beaconManager.Ranging += (object sender, BeaconManager.RangingEventArgs e) => RunOnUiThread(() => { if (e.Beacons.Count == 0) { noBeacons.Visibility = ViewStates.Visible; } else if (noBeacons.Visibility == ViewStates.Visible) { noBeacons.Visibility = ViewStates.Gone; } if (progressBar.Visibility == ViewStates.Visible) { progressBar.Visibility = ViewStates.Invisible; } ((BeaconAdapter)ListAdapter).Beacons.Clear(); ((BeaconAdapter)ListAdapter).Beacons.AddRange(e.Beacons); ((BeaconAdapter)ListAdapter).NotifyDataSetChanged(); }); //estimote loggin, optional #if DEBUG Estimote.EnableDebugLogging(true); #endif }