In Android, I can find paired Bluetooth devices by using the discovering process and listening to the ACTION_FOUND broadcast intent. To initate this, I use this code:
var filter = new IntentFilter();
filter.AddAction(BluetoothDevice.ActionFound);
new MyBroadcastReceiver().RegisterFilter(this, filter);
var bluetoothManager = GetSystemService(Context.BluetoothService) as BluetoothManager;
bluetoothManager.Adapter.StartDiscovery();
… and this receiver:
public class MyBroadcastReceiver: BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
if (intent.Action == BluetoothDevice.ActionFound)
{
var bluetoothDevice = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice, Java.Lang.Class.FromType(typeof(BluetoothDevice)));
if (bluetoothDevice.BoundState == Bond.Bonded)
{
// Do some stuff
}
}
}
}
Unfortunately, the started discovering process will be terminated after about 12 seconds, but I would like to be notified immediately, if a paired Bluetooth device is available for a RFCOMM serial connection.
On Windows, I can do this by using the DeviceWatcher with this code:
var deviceWatcher = DeviceInformation.CreateWatcher(BluetoothDevice.GetDeviceSelectorFromPairingState(true));
deviceWatcher.Added += DeviceWatcher_Added;
Is there a solution like this available for Android too? Maybe also working for a notification, when the Bluetooth device left the area?