Android locked fullscreen

后端 未结 2 1932
广开言路
广开言路 2021-01-14 17:23

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.

相关标签:
2条回答
  • 2021-01-14 18:02

    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.
    0 讨论(0)
  • 2021-01-14 18:26

    One way to do it is to use an overlay which requires SYSTEM_ALERT_WINDOW permission, while setting up the app with/as a service. See the prior answer with code example by yoah at Disable home button in android toddler app?

    0 讨论(0)
提交回复
热议问题