Permalink
Browse files

making the broadcast receiver work correctly when intent action const…

…ants are strings
  • Loading branch information...
1 parent d015589 commit 87f04e1a56efd6c76a75710046ad1bbba664d142 @rebeccanesson rebeccanesson committed May 2, 2012
@@ -2,6 +2,7 @@
import android.content.Context;
import android.content.Intent;
+import android.media.AudioManager;
public class BroadcastReceiver extends android.content.BroadcastReceiver {
@@ -14,7 +15,9 @@ public BroadcastReceiver(PlaybackService service) {
@Override
public void onReceive(Context context, Intent intent) {
- if (mService.isPlaying() && intent.getAction() == Intent.ACTION_HEADSET_PLUG
+ if (mService.isPlaying() &&
+ (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG) ||
+ intent.getAction().equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY))
&& intent.getIntExtra("state", 0) == 0) {
mService.pause();
}
@@ -106,6 +106,7 @@ public void onStart(Intent intent, int startId) {
mBroadcastReceiver = new BroadcastReceiver(this);
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_HEADSET_PLUG);
+ filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
getBaseContext().registerReceiver(mBroadcastReceiver, filter);
}

0 comments on commit 87f04e1

Please sign in to comment.