Here is my broadcast receiver code:
[BroadcastReceiver]
[IntentFilter(new[] { BluetoothDevice.ActionFound })]
public class BlueToothDeviceBroadcastReciever : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
IBlueToothService service = Xamarin.Forms.DependencyService.Get();
string action = intent.Action;
if (action == BluetoothDevice.ActionFound)
{
BluetoothDevice newDevice = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice);
service.DeviceAdded(new Models.BluetoothDevice(newDevice.Name, newDevice.Address));
}
}
}
Here is my on-resume code for the activity:
protected override void OnResume()
{
if(bluetoothDeviceReceiver == null)
{
bluetoothDeviceReceiver = new BlueToothDeviceBroadcastReciever();
}
RegisterReceiver(bluetoothDeviceReceiver, new IntentFilter(BluetoothDevice.ActionFound));
base.OnResume();
}
and I am calling start scan once the user clicks a button:
public void StartScan()
{
BluetoothAdapter adapter = BluetoothAdapter.DefaultAdapter;
if(adapter.IsEnabled)
{
adapter.StartDiscovery();
}
}
I cant get the OnReceive to fire inside the broadcast receiver
did I miss anything?
Thanks!