简体   繁体   English

如何通过蓝牙扫描另一台设备- Xamarin

[英]How to scan for another device through Bluetooth- Xamarin

I'm developing Xamarin application using Visual Studio 2019. I have to connect to another device through Bluetooth and send some data and receive acknowledgement back.我正在使用 Visual Studio 2019 开发 Xamarin 应用程序。我必须通过蓝牙连接到另一台设备并发送一些数据并接收回确认。 Tried these two samples out试用了这两个样品

  1. https://github.com/msthrax/BLEApp https://github.com/msthrax/BLEApp

    and

  2. https://github.com/didourebai/BLEPluginDemo . https://github.com/didourebai/BLEPluginDemo

But didn't help me while scanning for nearby Bluetooth devices , since the below codes are not giving expected result respectively..但是在扫描附近的蓝牙设备时没有帮助我,因为下面的代码分别没有给出预期的结果。

1. 1.

listView_DeviceList.ItemsSource = CrossBluetooth.Adaptor.GetListOfDiscoveredDevices();

and

2. 2.

adapter.DeviceDiscovered += (s, a) =>
{
    deviceList.Add(a.Device);
};

Both Bluetooth and location turned on in my devices.我的设备中的蓝牙和位置都已打开。 Can anyone let me know the possibilities of problem here.任何人都可以让我知道这里出现问题的可能性。 I don't have any build errors in both of the above samples.我在上述两个示例中都没有任何构建错误。 Whereas, I have one surprise also.然而,我也有一个惊喜。 Below line is giving proper result, which is of no use for me currently.下面一行给出了正确的结果,目前对我没有用。

listView_PairedDeviceList.ItemsSource = CrossBluetooth.Adaptor.GetPairedDevices();

After enabling the Location Permission for the app(earlier, I turned on Device Location, but we should allow the app to get device location ), all my above problems are solved out.为应用程序启用位置权限后(之前,我打开了设备位置,但我们应该允许应用程序获取设备位置),我上面的问题都解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM