registerMediaButtonEventReceiver / handling volume buttons issue
<p>In my application I need to process physical button events such as volume button clicks. For that I'm using audiomanager's registerMediaButtonEventReceiver method. There's an <a href="http://android-developers.blogspot.com/2010/06/allowing-applications-to-play-nicer.html" rel="nofollow">article</a> relevant to my situation, though I can't get it working.</p>

<p>Here's code I'm using:</p>

<pre><code>public class VolumeBroadcastActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        AudioManager manager = (AudioManager) getSystemService(AUDIO_SERVICE);
        manager.registerMediaButtonEventReceiver(new ComponentName(getPackageName(), RemoteControlReceiver.class.getName()));
    }

    public class RemoteControlReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {

            Toast.makeText(VolumeBroadcastActivity.this, "1",1).show();
            if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
            }
        }
    }
}

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="localhost.volume.broadcast"
    android:versionCode="1"
    android:versionName="1.0" &gt;

    &lt;uses-sdk android:minSdkVersion="10" /&gt;

    &lt;application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" &gt;
        &lt;activity
            android:name=".VolumeBroadcastActivity"
            android:label="@string/app_name" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;
                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
        &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;
    &lt;/application&gt;

&lt;/manifest&gt;
</code></pre>
