Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Broadcast reciever isn't working

Hello,

I am trying to detect when the user disconnects their bluetooth headphones

I made this simple reciever:

[BroadcastReceiver]
    [IntentFilter(new[] { AudioManager.ActionAudioBecomingNoisy })]
    class AudioBecomingNoisyBroadcastReciever : BroadcastReceiver
    {
        public override void OnReceive(Context context, Intent intent)
        {
            Toast.MakeText(Application.Context, "NOISY", ToastLength.Long).Show();
            System.Diagnostics.Debug.WriteLine("NOISY");
        }
    }
}

But it isn't working for some reason. When I connect my bluetooth headphones, start playback and then disconnect them, the OnReceive() simply never gets called.
My suspicion is that the AudioManager.ActionAudioBecomingNoisy part might be wrong, as I was unable to find any example of what the ACTION_AUDIO_BECOMING_NOISY android flag is supposed to look on xamarin, so I'm assuming the xamarin's alternative of this flag is the AudioManager.ActionAudioBecomingNoisy constant.

Any idea what I'm doing wrong here?

Tagged:
Sign In or Register to comment.