Hi,
I am working on a Bluetooth Low Energy scanner for Android, which has to scan every X minutes all nearly devices, getting all services and characteristics, and sending them to a HTTP server. This task has to be executed in background, so I figured I should use Services, but I dont know if that can work correctly with BLE scans.
BLE scans mainly use async methods and callbacks, is it possible to set all this process in a task or something I can control with a background service ?
By the way, I found many things about background services, and I don't get what I should use ... Can someone take a few minutes to explain me ? ![]()
Thanks !
Do you want to scan Bluetooth in Background service?
You could try to use Bluetooth LE plugin for Xamarin.
It requires ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION BLUETOOTH BLUETOOTH_ADMIN permissions.
List<IDevice> deviceList;
[return: GeneratedEnum]
public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
{
var ble = CrossBluetoothLE.Current;
var adapter = CrossBluetoothLE.Current.Adapter;
deviceList = new List<IDevice>();
adapter.DeviceDiscovered += (s, a) => {
deviceList.Add(a.Device);
} ;
Task task = new Task(() => adapter.StartScanningForDevicesAsync());
task.Start();
return StartCommandResult.NotSticky;
}If you still need help regarding Xamarin Development feel free to contact me.