async void Button_OnClickedScanToggle(Object obj, EventArgs e)
        {
            if (firsttime && BLEProfileManager.bleprofile.Devices.Count == 0)
            {
                BLEProfileManager.init();
                firsttime = false;
            }


            Task.Delay(3000);
            if (BLEProfileManager.bleprofile.IsScanning)
            {
                this.scan?.Dispose();
                //BLEProfileManager.bleprofile.Adapter.StopScanningForDevicesAsync();
                this.ScanText.Text = BLEProfileManager.bleprofile.Adapter.IsScanning ? "Stop Scan" : "Scan";
                //this.Devicesl.ItemsSource = BLEProfileManager.bleprofile.Devices;
                var counterscan = 0;
                while (BLEProfileManager.bleprofile.IsScanning)
                {
                    //DisplayAlert("Question?", "Do you have Smartband Alert product?", "Yes", "No");
                    var answer = await DisplayAlert("Wait Please", "Looking for SmartBand Alert", "Ok", "" + counterscan ++);

                    // _userDialogs.ShowLoading($"Disconnect in {counterscan++}s...", MaskType.Black);

                    if (BLEProfileManager.bleprofile.Devices.Count != 0)
                    {
                        this.Devicesl.ItemsSource = BLEProfileManager.bleprofile.Devices;
                        this.ScanText.Text        = BLEProfileManager.bleprofile.Adapter.IsScanning ? "Stop Scan" : "Scan";
                    }
                }
            }
            else
            {
                this.ScanText.Text = BLEProfileManager.bleprofile.Adapter.IsScanning ? "Stop Scan" : "Scan";
                //BLEProfileManager.ScanForDevices();
                if (BLEProfileManager.bleprofile.Devices.Count != 0)
                {
                    this.Devicesl.ItemsSource = BLEProfileManager.bleprofile.Devices;

                    /*string s = BLEProfileManager.bleprofile.Devices.FirstOrDefault().Device.State.ToString();
                     * if (s.Equals("Disconnected"))
                     * {
                     *  BLEProfileManager.bleprofile.Adapter.ConnectToDeviceAsync(BLEProfileManager.bleprofile.Devices.FirstOrDefault().Device);
                     * }
                     * else
                     *  this.SyststateL.Text = "Connected: " + BLEProfileManager.bleprofile.Devices.FirstOrDefault().IsConnected.ToString();*/
                }
                else
                {
                    this.SyststateL.Text = "Connected: Couldt Find";
                    BLEProfileManager.init();
                }
            }
        }
Example #2
0
        async void Button_OnClickedScanToggle(Object obj, EventArgs e)
        {
            /*if (firsttime && BLEProfileManager.bleprofile.Devices.Count == 0)
             * {
             *  BLEProfileManager.init();
             *  firsttime = false;
             * }*/

            if (BLEProfileManager.bleprofile.ble.IsOn)
            {
                Task.Delay(3000);
                if (BLEProfileManager.bleprofile.IsScanning)
                {
                    //BLEProfileManager.bleprofile.Adapter.StopScanningForDevicesAsync();
                    this.ScanText.Text = BLEProfileManager.bleprofile.Adapter.IsScanning ? "Stop Scan" : "Scan";
                    //this.Devicesl.ItemsSource = BLEProfileManager.bleprofile.Devices;
                    var counterscan = 0;
                    while (BLEProfileManager.bleprofile.IsScanning)
                    {
                        //DisplayAlert("Question?", "Do you have Smartband Alert product?", "Yes", "No");
                        var answer = await DisplayAlert("Wait Please", "Looking for SmartBand Alert", "Ok", "" + counterscan ++);

                        // _userDialogs.ShowLoading($"Disconnect in {counterscan++}s...", MaskType.Black);

                        if (BLEProfileManager.bleprofile.Devices.Count != 0)
                        {
                            this.theBTunits.ItemsSource = BLEProfileManager.bleprofile.Devices;
                            this.ScanText.Text          = BLEProfileManager.bleprofile.Adapter.IsScanning ? "Stop Scan" : "Scan";
                        }
                    }
                }
                else
                {
                    this.ScanText.Text = BLEProfileManager.bleprofile.Adapter.IsScanning ? "Stop Scan" : "Scan";
                    //BLEProfileManager.ScanForDevices();
                    if (BLEProfileManager.bleprofile.Devices.Count != 0)
                    {
                        this.theBTunits.ItemsSource = BLEProfileManager.bleprofile.Devices;
                    }
                    else
                    {
                        //this.SyststateL.Text = "Connected: Couldt Find";
                        BLEProfileManager.init();
                    }
                }
            }
            else
            {
                DisplayAlert("Error: Bluetooth is off?", "Turn on the Bluetooth?", "OK");
            }
        }