简体   繁体   English

在Android 4.0+中禁用主页按钮

[英]Disable Home button in Android 4.0+

I'm trying to replace the stock lock screen with my own app. 我正在尝试用我自己的应用程序替换股票锁定屏幕。
In my code, i want to disable the Home button. 在我的代码中,我想禁用主页按钮。
I know how to do this in Android 2.3 and below, 我知道如何在Android 2.3及更低版本中执行此操作,
but the same code doesn't work with Android 4.0+ (return to desktop when Home button pressed) 但相同的代码不适用于Android 4.0+(按下Home按钮时返回桌面)

Recently I found out an app called MiHome which has its own lock screen and is able to disable the Home button. 最近我发现了一个名为MiHome的应用程序,它有自己的锁定屏幕,可以禁用主页按钮。
Does anyone know how it achieves this??? 有谁知道它是如何实现这一点的???

There is no way to intercept the home button on Android, unless you make your app the home screen. 除非您将应用程序设置为主屏幕,否则无法拦截Android上的主页按钮。 This is for security reasons, so that malicious apps cannot take over your device by overriding all the buttons that can exit. 这是出于安全原因,因此恶意应用程序无法通过覆盖可以退出的所有按钮来接管您的设备。 The home button is the one sure shot way to be able to leave any app. 主页按钮是一种可以离开任何应用程序的确定镜头方式。

If you want to handle the HOME button, implement a home screen. 如果要处理HOME按钮,请实现主屏幕。

Mucking with the home button is disabled for security/reliability reasons in ICS. 出于安全性/可靠性原因,在ICS中禁用使用主页按钮进行操作。 (Most apps use it for evil than good) (大多数应用程序使用它来辟邪而不是好)

Please refer to the following questions for workarounds. 有关变通方法,请参阅以下问题。

  1. how can I disable android 4.0 home button 如何禁用android 4.0主页按钮
  2. override Home key in android ICS 覆盖android ICS中的Home键
  3. Disable Home Button in Android ICS (4.0) 禁用Android ICS中的主页按钮(4.0)

Seems like the only way is to implement a home screen 似乎唯一的方法是实现主屏幕

Try this 尝试这个

   params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.TOP;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            } else {
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            }
    mOverlay = (RelativeLayout) inflater
                    .inflate(R.layout.main, (ViewGroup) null);

    mOverlay.setFitsSystemWindows(false);
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
            mWindowManager = (WindowManager) context
                    .getSystemService(Context.WINDOW_SERVICE);
            mWindowManager.addView(mOverlay, params);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM