Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Broadcast receiver not firing on receive

$
0
0

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<IBlueToothService>();
         string action = intent.Action;
         if (action == BluetoothDevice.ActionFound)
         {
              BuetoothDevice 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!


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>