【问题标题】:Android - How to capture volume buttons events when the phone is in stand byAndroid - 如何在手机处于待机状态时捕获音量按钮事件
【发布时间】:2013-05-28 07:21:08
【问题描述】:

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

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

【问题讨论】:

    标签: android events mobile button


    【解决方案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-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 1970-01-01
      • 2012-05-13
      • 1970-01-01
      相关资源
      最近更新 更多