如何禁用主页和其他系统按钮的Andr​​oid?按钮、系统、主页、oid

2023-09-11 11:54:03 作者:北沐城歌

我需要禁用家庭和其他系统的按钮在我的Andr​​oid应用程序。

I need to disable Home and other system buttons in my Android application.

示例: MX播放器(看到谷歌播放) - 你可以preSS锁定图标,播放器屏幕,并锁定所有的硬件​​和软件系统的按钮。

Example: MX Player (see at Google Play) - you can press "lock" icon at player screen and it locks all hardware and software system buttons.

它工作正常没有生根。

It works fine WITHOUT ROOTING.

我在不同的Andr​​oid版本的一些设备进行了测试。我试图拆开儿童锁(插件),但不知道它是如何工作的呢。

I tested it on some devices with different Android versions. I tried to disassemble Kids Lock (plugin) but has no clue how it works yet.

我需要 MX播放器相同的解决方案,如儿童锁(插件): - 禁用主页,返回和所有其他系统的按钮

I need same solution like the Kids Lock (plugin) for MX Player: - disable Home, Back and all other system buttons.

有什么建议?

推荐答案

首先,请想想漫长而艰难的,如果你真的要禁用首页按钮或其他任何按钮为此事(如返回按钮),这是不是应该做(至少大部分的时间,这是一个不好的设计)。我只能为自己说话,但如果我下载了一个应用程序,并没有让我做一些像点击操作系统按钮,接下来的事情我做的是卸载该应用程序,并留下了非常不好的审查。我也相信,你的应用程序不会在App Store上的特色。

First of, please think long and hard if you really want to disable the Home button or any other button for that matter (e.g. the Back button), this is not something that should be done (at least most of the times, this is a bad design). I can speak only for myself, but if I downloaded an app that doesn't let me do something like clicking an OS button, the next thing I do is uninstall that app and leave a very bad review. I also believe that your app will not be featured on the App Store.

现在...

注意 MX播放器要求允许利用其他应用程序的顶部: 既然你不能覆盖首页按钮安卓设备(至少在最新的操作系统版本没有)。 MX播放器绘制本身你的发射器的顶部,当您锁定关于首页按钮的应用程序,并点击。 要看到一个例子就是有点更加简单和直接的了解,你可以看到的 Facebook的Messenger的应用。

Notice that MX Player is asking permission to draw on top of other applications: Since you cannot override the Home button on Android device (at least no in the latest OS versions). MX Player draws itself on top of your launcher when you "lock" the app and clicks on the Home button. To see an example of that is a bit more simple and straight forward to understand, you can see the Facebook Messenger App.

当我被要求提供一些有关MX播放器状态栏导航栏详细信息压倒一切,我编辑我的答案,包括这些话题。

As I was asked to provide some more info about MX Player Status Bar and Navigation Bar "overriding", I'm editing my answer to include these topics too.

首先第一件事情,MX播放器采用沉浸式全屏模式(的 DevBytes视频)在奇巧。 Android 4.4系统(API等级19)引入了新的SYSTEM_UI_FLAG_IMMERSIVE标志setSystemUiVisibility()让您的应用程序去真正的全屏幕。这个标志,在与SYSTEM_UI_FLAG_HIDE_NAVIGATION和SYSTEM_UI_FLAG_FULLSCREEN标志,隐藏导航栏和状态栏,让您的应用程序捕获屏幕上的所有触摸事件。

First thing first, MX Player is using Immersive Full-Screen Mode (DevBytes Video) on KitKat. Android 4.4 (API Level 19) introduces a new SYSTEM_UI_FLAG_IMMERSIVE flag for setSystemUiVisibility() that lets your app go truly "full screen." This flag, when combined with the SYSTEM_UI_FLAG_HIDE_NAVIGATION and SYSTEM_UI_FLAG_FULLSCREEN flags, hides the navigation and status bars and lets your app capture all touch events on the screen.

当启用身临其境的全屏模式下,你的活动将继续接收所有触摸事件。用户可以揭示系统吧沿所在的系统栏通常出现在区域内向刷卡。这将清除SYSTEM_UI_FLAG_HIDE_NAVIGATION标志(而SYSTEM_UI_FLAG_FULLSCREEN标志,如果应用),以使系统棒变得可见。这也触发你的View.OnSystemUiVisibilityChangeListener,如果设置。不过,如果你想在系统栏再次片刻后自动隐藏,而是可以使用SYSTEM_UI_FLAG_IMMERSIVE_STICKY旗。需要注意的是粘性版本旗不触发任何听众,如系统扶手的这种模式下暂时示出的是处于过渡状态。

When immersive full-screen mode is enabled, your activity continues to receive all touch events. The user can reveal the system bars with an inward swipe along the region where the system bars normally appear. This clears the SYSTEM_UI_FLAG_HIDE_NAVIGATION flag (and the SYSTEM_UI_FLAG_FULLSCREEN flag, if applied) so the system bars become visible. This also triggers your View.OnSystemUiVisibilityChangeListener, if set. However, if you'd like the system bars to automatically hide again after a few moments, you can instead use the SYSTEM_UI_FLAG_IMMERSIVE_STICKY flag. Note that the "sticky" version of the flag doesn't trigger any listeners, as system bars temporarily shown in this mode are in a transient state.

二:隐藏状态栏 第三:隐藏导航栏 请注意,虽然使用沉浸式全屏只适用于奇巧,隐藏状态栏导航栏不仅是奇巧

Second: Hiding the Status Bar Third: Hiding the Navigation Bar Please note that although using immersive full screen is only for KitKat, hiding the Status Bar and Navigation Bar is not only for KitKat.

我没有太多要说的第二和第三,你的想法,我相信,这是一个快速阅读在任何情况下。只要确保你抓紧View.OnSystemUiVisibilityChangeListener.

I don't have much to say about the 2nd and 3rd, You get the idea I believe, it's a fast read in any case. Just make sure you pay close attention to View.OnSystemUiVisibilityChangeListener.

我添加了一个要点,说明了我的意思,它是不完整的,需要一些固定但你的想法。 https://gist.github.com/Epsiloni/8303531

I added a Gist that explains what I meant, it's not complete and needs some fixing but you'll get the idea. https://gist.github.com/Epsiloni/8303531

祝你好运落实这一点,玩得开心!

Good luck implementing this, and have fun!