检测电源按钮三presses [英] detecting three presses of power button

查看:135
本文介绍了检测电源按钮三presses的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的是新。我试图让将在后台运行,并检测电源按钮三个快速presses的应用程序。我看过了很多,但不能清除我的困惑。任何人都可以请给我一些建议吗? TIA。

I'm new in Android. I'm trying to make an app that will run in background and detect three rapid presses of the power button. I've looked up a lot, but could not clear my confusion. can anyone please give me some suggestion? TIA.

推荐答案

声明静态变量外的onkeydown 并增加内部变量的onkeydown 并返回该值是否等于3并在最后再次等于静态变量等于0;

Declare the static variable outside the onKeyDown and increment variable inside the onKeyDown and return if the value is equal to 3 and at the end again equal the static variable equal to 0;

static int i=0;
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
       i++;
        if(i==3){
    //do something

//at the end again i=0;
        }

    }
    return super.onKeyDown(keyCode, event);
}

这篇关于检测电源按钮三presses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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