AudioManager and system volume change receiver
<p>I've followed instructions on <a href="http://android-developers.blogspot.com/2010/06/allowing-applications-to-play-nicer.html" rel="nofollow">this page</a> until "Preparing your code for Android 2.2 without restricting it to Android 2.2". Even if I'm building against 2.3 version, I guess it should be working at this point but it's not. I've registered a receiver in manifest:</p>

<pre><code>&lt;receiver android:name="RemoteControlReceiver"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="android.intent.action.MEDIA_BUTTON" /&gt;
    &lt;/intent-filter&gt;
&lt;/receiver&gt;
</code></pre>

<p>created a class for RemoteControlReceiver declaration:</p>

<pre><code>public class RemoteControlReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "onReceive", Toast.LENGTH_SHORT).show();
    }
}
</code></pre>

<p>and finally boostrapped it in the starting activity.</p>

<pre><code>private AudioManager _audioManager;
private ComponentName _componentName;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    _audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    _componentName = new ComponentName(getPackageName(), RemoteControlReceiver.class.getName());
}

@Override
protected void onResume() {
    super.onResume();

    _audioManager.registerMediaButtonEventReceiver(_componentName);

    _audioManager.requestAudioFocus(new OnAudioFocusChangeListener() {

            @Override
            public void onAudioFocusChange(int focusChange) {
                    Toast.makeText(getApplicationContext(), "onFocusChanged", Toast.LENGTH_SHORT).show();
            }
    }, AudioManager.STREAM_MUSIC, 0);
}
</code></pre>

<p>Could you point out what am I missing here ? I have an assumption that in order to receive thodse messages I my activity has to play any media stuff. I gonna test it right away.</p>

<p>P.S. As you see I've even added some uneccessary code - don't pay attention to requestAudioFocus.</p>

<p>Thanks for any suggestions.</p>
