How I can receive hardware key events in sleep mode?

一世执手 提交于 2019-12-04 13:12:37
public class YourBoardcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
                if (Intent.ACTION_CAMERA_BUTTON.equals(intent.getAction())) {
                        Intent main = new Intent();// 
                }
        }
}

And in your Manifest :

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

The only way I think you could do that is with a BroadcastReceiver, but it seems that the volume buttons do not generate an Intent when the screen is off (see here). The closest thing you might be able to do is use the camera button to do something similar.

Perhaps it is better this way, anyway, though. I imagine it would annoy users if their phone called 911 while in their pocket because of the volume buttons, or the camera button too for that matter. Also, it's not something I would expect to happen.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!