![](/img/trans.png)
[英]Bluetooth Scan throwing ArgumentOutOfRangeException in Xamarin.iOS
[英]Xamarin Bluetooth Scan
今天,我開始使用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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.