简体   繁体   中英

searching nearby available bluetooth in Xamarin android 9

我想搜索可用的蓝牙,但找不到适用于 Xamarin android 9 的解决方案,

Firstly, add the following permissions to AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

And for Bluetooth scan you could use the plugin Plugin.BLE from Nuget .

Usage

ObservableCollection<Plugin.BLE.Abstractions.Contracts.IDevice> deviceList;


deviceList = new ObservableCollection<Plugin.BLE.Abstractions.Contracts.IDevice>();
var adapter = CrossBluetoothLE.Current.Adapter;

adapter.DeviceDiscovered += (s, a) =>
{
   Console.WriteLine(a.Device.Name);
   deviceList.Add(a.Device);
};
await adapter.StartScanningForDevicesAsync();

For more details and usage of the plugin you could check https://github.com/xabre/xamarin-bluetooth-le .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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