0

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

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

4

1 回答 1

-1

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

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>

于 2013-05-28T07:28:16.133 回答