locked
Unable to connect a bluetooth. RRS feed

  • Question

  • User364101 posted

    Hi Everyone, I am trying to accessing the bluetooth devices around the device with below code-->

        async void btnScan_Clicked(System.Object sender, System.EventArgs e)
         {
    
            deviceList.Clear();
            adapter.DeviceDiscovered += (s, a) =>
            {
                    if (deviceList.Contains(a.Device))
                        return;
                    else
                        deviceList.Add(a.Device);
    
    
            };
            if (!ble.Adapter.IsScanning)
            {
    
                await adapter.StartScanningForDevicesAsync();
    
            }
            if (deviceList.Count != 0) 
            {
                for (int i = 0; i < deviceList.Count; i++)
                {
                    DeviceSearch deviceSearch1 = new DeviceSearch();
                    deviceSearch1.Id = (deviceList[i]).NativeDevice.ToString();//Id.ToString();
                    deviceSearch1.Name = deviceList[i].Name;
                    deviceSearches.Add(deviceSearch1);
                }
            }
    
        }
    
    
    private async void lv_ItemSelected(object sender, SelectedItemChangedEventArgs e)
            {
               try
               {
                  if (lv.SelectedItem == null)
                  {
                        return;
                     }
                    device = lv.SelectedItem as IDevice;
                      string asd = device.ToString();
                     await adapter.ConnectToDeviceAsync(device);
             }
            catch (DeviceConnectionException ex)
            {
                Debug.WriteLine("BLE connect DCE ex msg: " + ex.Message);
                Debug.WriteLine("e.Device.Name = " + device.Name);
            }
    
        }
    

    The scan result don't work properly , this doesn't scan Samsung Level U device. Most of the devices are blank. I have used Plugin.Ble in the application. While trying to connect a device , getting GattCallBack error .

    First off all I am not getting every bluetooth devices, most of the devices contains blank name. Please suggest what should I do.

    Wednesday, January 29, 2020 7:02 AM

All replies

  • User387683 posted

    You could refer to the link below, it provide two samples to scan bluetooth devices. https://github.com/xabre/xamarin-bluetooth-le https://github.com/conceptdev/xamarin-forms-samples/tree/master/BluetoothTISensor

    Thursday, January 30, 2020 2:39 AM