After reading the android dev-guide and some posts here, I have implemented a simple solution to capture a HEADSET UNPLUG event in my tablet running Android 2.3.3.
Unfortunately it seems I’m missing something since the onReceive() event never gets captured.
Bellow is the implemented code:
public class MusicIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
Toast.makeText(context, "Headphones disconnected.", Toast.LENGTH_SHORT).show();
}
}
}
And in the android manifest file:
<receiver android:name=".MusicIntentReceiver">
<intent-filter>
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
</intent-filter>
</receiver>
What am I missing?
The NOISY filter gets triggered when audio output sources change, and might cause funky stuff.
The correct filter for headset plug should be:
The Manifest should read: