Android-当手机处于待机状态时,如何捕获音量按钮事件

Android-当手机处于待机状态时,如何捕获音量按钮事件,android,events,mobile,button,Android,Events,Mobile,Button,我需要你的帮助。我想实现音量按钮 我想知道,当手机处于待机状态时,如何捕获音量按钮事件?创建一个广播接收器,用于接收这样的按钮事件 public class YourBoardcastReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())

我需要你的帮助。我想实现音量按钮


我想知道,当手机处于待机状态时,如何捕获音量按钮事件?

创建一个广播接收器,用于接收这样的按钮事件

public class YourBoardcastReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
    if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
        /* handle media button intent here by reading contents */
        /* of EXTRA_KEY_EVENT to know which key was pressed    */
    }
}
}

而且明显地

<receiver android:name="YourBoardcastReceiver">
            <intent-filter>
                    <action android:name="android.intent.action.SCREEN_ON" />
            </intent-filter>