gpt4 book ai didi

c# - Xamarin 蓝牙扫描

转载 作者:太空狗 更新时间:2023-10-29 16:33:28 24 4
gpt4 key购买 nike

今天我开始使用 C# 进行开发,我尝试扫描一个信标。这就是我走了多远..

        protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);

BluetoothAdapter oBluetoothAdapter = BluetoothAdapter.DefaultAdapter;
BluetoothLeScanner oScanner = oBluetoothAdapter.BluetoothLeScanner;

ScanCallback oCallback;



if(!oBluetoothAdapter.IsEnabled)
{
StartActivity(new Intent(BluetoothAdapter.ActionRequestEnable));
}
else
{
oScanner.StartScan(oCallback);
}
}

问题是我不知道如何使用 StartScan 函数的回调参数。有人可以告诉我如何正确使用回调吗?

最佳答案

在 android 上的实现是这样的:

_Manager = (BluetoothManager)appContext.GetSystemService("bluetooth");
_Adapter = _Manager.Adapter;
_LeScanner = _Adapter.BluetoothLeScanner;
_BluetoothScanCallback = new BluetoothScanCallback();

然后当您开始扫描时,它会是这样的:

_LeScanner.StartScan(_BluetoothScanCallback);

其中 BluetoothScanCallback 将使用如下方式实现:

public class BluetoothScanCallback : ScanCallback
{
public override void OnScanResult([GeneratedEnum] ScanCallbackType callbackType, ScanResult result)
{
base.OnScanResult(callbackType, result);
}
}

关于c# - Xamarin 蓝牙扫描,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34182618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com