[英]Xamarin Bluetooth Scan
today i started developing with C# and i tried to scan for a beacon. 今天,我开始使用C#进行开发,并尝试扫描信标。 This is how far i came..
这是我走多远。
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);
}
}
The Problem is that i dont know how to use the Callback Parameter of the StartScan function. 问题是我不知道如何使用StartScan函数的回调参数。 Can sombody please tell me how to use the callback right ?
有人可以告诉我如何使用回调吗?
On android the implementation would be something like this: 在android上,实现将如下所示:
_Manager = (BluetoothManager)appContext.GetSystemService("bluetooth");
_Adapter = _Manager.Adapter;
_LeScanner = _Adapter.BluetoothLeScanner;
_BluetoothScanCallback = new BluetoothScanCallback();
Then when you start your scan it would be something like this: 然后,当您开始扫描时,将如下所示:
_LeScanner.StartScan(_BluetoothScanCallback);
where BluetoothScanCallback
would be implemented using something like: 使用以下方法可以实现
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.