KEY code_POWER只出动长preSS [英] KEYCODE_POWER only dispatched on long press

查看:167
本文介绍了KEY code_POWER只出动长preSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这个键只得到派出一个长preSS。我试着让电源按钮正常preSS静音林格流中的当前正在播放的音频拥有它。它仅适用于长期preSS,正常preSS关闭屏幕。我需要它正常preSS工作。

Why does this key only get dispatched on a long press. Im trying to have it so that normal press of the power button mutes the currently playing audio in the Ringer stream. It only works on long press, normal press turns the screen off. I need it to work on normal press.

@Override
public boolean dispatchKeyEvent(KeyEvent event) {

        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_POWER:
            if (ringer == null)
                return super.dispatchKeyEvent(event);

            if (!mute)
                if (ringer.isRinging())
                    ringer.stopRing();
                else if (!ringer.isRinging())
                    ringer.ring();

            mute = !mute;
            return true;
        }
return super.dispatchKeyEvent(event);

}

推荐答案

这需要比这更捕捉到的POWER键的存在pressed。

It takes more than that to capture the POWER button being pressed.

这是在由谷歌的目的完成,这样pventing任何用户输入和阻止硬件按钮恶意应用程序无法接管你的设备由$ P $。除此之外覆盖POWER按钮应该做只是如果对于一个很好的理由。

This is done on purpose by Google so that malicious applications cannot take over your device by preventing any user input and blocking hardware buttons. Besides that overriding the POWER button should be done only if there is a very good reason for that.

如果你想知道如何做到这一点然后访问<一个href=\"http://stackoverflow.com/questions/3703071/how-to-hook-into-the-power-button-in-android\">THIS问题和检查最受好评的答案。

If you want to know how to do it then visit THIS question and check the top rated answer.

PS。搜索下一次。

这篇关于KEY code_POWER只出动长preSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆