Android的 - 捕获/ SUP preSS家庭和结束呼叫按钮的事件? [英] Android - capture/suppress Home and EndCall buttons events?

查看:110
本文介绍了Android的 - 捕获/ SUP preSS家庭和结束呼叫按钮的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你曾经试图写一个Android的应用程序更衣室肯定你遇到这个问题:

If you ever tried to write a locker app on Android sure you meet this problem:

boolean mBackPressed = false;

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            mBackPressed = true;
            break;
        case KeyEvent.KEYCODE_MENU:
            if (mBackPressed)
                unLock();
            break;
        default:
            mBackPressed = false;
            showMessage();
            break;
        }
    }
    return true;
}

private void showMessage() {
    Toast.makeText(getBaseContext(), "Back + Menu", Toast.LENGTH_SHORT)
            .show();
}

private void unLock() {
    this.setResult(Activity.RESULT_OK);
    this.finish();
}

好像是的onkeydown过滤掉所有的键,而是后退和菜单...
好吧,这不是真的!的Home键依然会带给你主屏幕和结束通话按钮将运行本地应用程序更衣室!

Seems like onKeyDown is filtering out all keys but "Back" and "Menu"...
Well, it's not true! Home button will still bring you Home screen and End Call button will run native Locker application!

研究员的那里也宣称这是一个问题:
如何从按结束键
问题首页上一页屏幕按钮
苏pressing关键presses的活动,特别是在选项菜单
发行4202:功能建议:允许拦截KEY code_CALL

Fellow's out there also claim it as a problem:
How to listen from ENDCALL button
problem With Home Back screen button
Supressing Key presses in Activity, especially in Options Menu
Issue 4202: Feature Suggestion: permission for intercepting KEYCODE_CALL

你知道什么解决办法来阻止其中的两个按钮?
是唯一的方法(经常) - 的 用C写的 的?

Do you know any workaround to block two those buttons?
Is the only way (as often) - write in C ?

推荐答案

可以的捕捉返回键很容易的。

我不认为你将能够拦截Home和End呼叫按钮。如果你能,这将允许恶意的应用程序,以prevent用户离开过它,有效地劫持了电话。

I don't think you'll be able to intercept the Home and End Call buttons. If you could, this would allow a malicious application to prevent a user ever leaving it, effectively hijacking the phone.

为您的应用程序的一个选择是使用的 android.intent.category.HOME 意图

An option for your application would be to write a replacement Home Screen using the android.intent.category.HOME Intent.

这篇关于Android的 - 捕获/ SUP preSS家庭和结束呼叫按钮的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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