Xamarin Forms Plugin.BLE Can';我找不到任何设备
我想写一个简单的应用程序,将比特发送到蓝牙设备。目前我不知道哪里出了问题,也不知道哪里出了问题。 我拥有所有权限,我正在请求它们(屏幕上只显示本地化) 扫描以发现以下设备的功能:Xamarin Forms Plugin.BLE Can';我找不到任何设备,xamarin,xamarin.forms,xamarin.android,bluetooth,bluetooth-lowenergy,Xamarin,Xamarin.forms,Xamarin.android,Bluetooth,Bluetooth Lowenergy,我想写一个简单的应用程序,将比特发送到蓝牙设备。目前我不知道哪里出了问题,也不知道哪里出了问题。 我拥有所有权限,我正在请求它们(屏幕上只显示本地化) 扫描以发现以下设备的功能: // Issue is here private async void ScanAsync() { try { Devices.Clear(); adapter.DeviceD
// Issue is here
private async void ScanAsync()
{
try
{
Devices.Clear();
adapter.DeviceDiscovered += (s, a) =>
{
Devices.Add(new Device_bluetooth() { Device = a.Device, Name = "Name: " + a.Device.Name.ToString(), Uuid = "UUID:" + a.Device.Id.ToString() });
};
if (!ble.Adapter.IsScanning)
{
await adapter.StartScanningForDevicesAsync();
}
}
catch (Exception ex)
{
await DisplayAlert("Notice", ex.Message.ToString(), "Error !");
}
Device\u bluetooth
是我用来存储设备的课程,我在下面的列表视图中显示它们:
<ListView x:Name="mylistview" ItemsSource="{Binding Devices}" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Height="100">
<StackLayout>
<Frame BackgroundColor="White"
HasShadow="true">
<StackLayout HeightRequest="100">
<Label Text="{Binding Name ,Mode=TwoWay}" />
<Label Text="{Binding Uuid ,Mode=TwoWay}" />
</StackLayout>
</Frame>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
请帮忙。我已经尝试了几乎所有的方法,但我无法应对。你申请了位置许可吗?@Cheesebaron是的,我申请了Xamarin的位置许可。基本信息这方面有什么更新吗?我这里有一个小项目,扫描一些mijia设备,效果很好。也许以此作为灵感。我无法复制你的问题。这似乎与安卓操作系统有关。我发现,通过我的代码,它有时会找到我需要的设备,有时却找不到该设备。一般来说,在搜索了大约5次之后,我总能找到我正在寻找的蓝牙设备。因此,可能不是代码或蓝牙模块的问题,而是安卓系统的问题
// Issue is here
private async void ScanAsync()
{
try
{
Devices.Clear();
adapter.DeviceDiscovered += (s, a) =>
{
Devices.Add(new Device_bluetooth() { Device = a.Device, Name = "Name: " + a.Device.Name.ToString(), Uuid = "UUID:" + a.Device.Id.ToString() });
};
if (!ble.Adapter.IsScanning)
{
await adapter.StartScanningForDevicesAsync();
}
}
catch (Exception ex)
{
await DisplayAlert("Notice", ex.Message.ToString(), "Error !");
}
<ListView x:Name="mylistview" ItemsSource="{Binding Devices}" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Height="100">
<StackLayout>
<Frame BackgroundColor="White"
HasShadow="true">
<StackLayout HeightRequest="100">
<Label Text="{Binding Name ,Mode=TwoWay}" />
<Label Text="{Binding Uuid ,Mode=TwoWay}" />
</StackLayout>
</Frame>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>