Android全屏锁定(Android locked fullscreen)

编程入门 行业动态 更新时间:2024-10-27 10:22:34
Android全屏锁定(Android locked fullscreen)

简单的问题,希望也是一个简单的答案; 是否有可能在Android上锁定全屏? 基本上隐藏吐司,隐藏家/后/开关,隐藏通知栏,使其从底部或顶部滑动不起作用。

研究一个可以从中受益的想法。 我知道做我描述的事情是不好的,但它针对的是非常年幼的孩子,他们随意点击/拖动偶尔将你的手机语言改为中文。

Simple question, hopefully a simple answer too; is it possible to lock fullscreen on Android? Basically hide toasts, hide home/back/switch, hide notification bar, make it so swiping from bottom or top doesn't work.

Working on an idea that would benefit greatly from this. I know it's bad to do what I described, but it's aimed at very young children who randomly tap/drag and occasionally change your phone language to Chinese by accident.

最满意答案

根据您定位的Android版本,您可以使用屏幕固定。

来自Android文档( https://developer.android.com/about/versions/android-5.0.html ):

屏幕固定

Android 5.0引入了一种新的屏幕固定API,可让您临时限制用户离开任务或被通知中断。 例如,如果您正在开发教育应用程序以支持Android或单一用途或信息亭应用程序的高风险评估要求,则可以使用此功能。 一旦您的应用激活屏幕固定,用户就无法看到通知,访问其他应用或返回主屏幕,直到您的应用退出该模式。

激活屏幕固定有两种方法:

手动:用户可以在设置>安全>屏幕固定中启用屏幕固定,并通过触摸最近屏幕中的绿色图钉图标选择要固定的任务。 以编程方式:要以编程方式激活屏幕固定,请从您的应用程序调用startLockTask()。 如果请求的应用程序不是设备所有者,则会提示用户进行确认。 设备所有者应用程序可以调用setLockTaskPackages()方法,以便在没有用户确认步骤的情况下使应用程序可以固定。

当任务锁定处于活动状态时,会发生以下行为:

状态栏为空白,隐藏用户通知和状态信息。 主页和最近的应用程序按钮被隐藏。 其他应用无法启动新活动。 当前应用程序可以启动新活动,只要这样做不会创建新任务。 当设备所有者调用屏幕固定时,用户将保持对应用程序的锁定,直到应用程序调用stopLockTask()。 如果屏幕固定是由另一个不是设备所有者的应用程序或由用户直接进行的活动,则用户可以通过同时按住“后退”和“最近”按钮退出。

Depending on the version of Android you're targeting you could use Screen Pinning.

From Android Documentation (https://developer.android.com/about/versions/android-5.0.html):

Screen pinning

Android 5.0 introduces a new screen pinning API that lets you temporarily restrict users from leaving your task or being interrupted by notifications. This could be used, for example, if you are developing an education app to support high stakes assessment requirements on Android, or a single-purpose or kiosk application. Once your app activates screen pinning, users cannot see notifications, access other apps, or return to the home screen, until your app exits the mode.

There are two ways to activate screen pinning:

Manually: Users can enable screen pinning in Settings > Security > Screen Pinning, and select the tasks they want to pin by touching the green pin icon in the recents screen. Programmatically: To activate screen pinning programmatically, call startLockTask() from your app. If the requesting app is not a device owner, the user is prompted for confirmation. A device owner app can call the setLockTaskPackages() method to enable apps to be pinnable without the user confirmation step.

When task locking is active, the following behavior happens:

The status bar is blank, and user notifications and status information are hidden. The Home and Recent Apps buttons are hidden. Other apps cannot launch new activities. The current app can start new activities, as long as doing so does not create new tasks. When screen pinning is invoked by a device owner, the user remains locked to your app until the app calls stopLockTask(). If screen pinning is activity by another app that is not a device owner or by the user directly, the user can exit by holding both the Back and Recent buttons.

更多推荐

本文发布于:2023-08-01 11:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1357767.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全屏   Android   fullscreen   locked

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!