noln / system-alert-window-example

Example project showing use of SYSTEM_ALERT_WINDOW permission on Android 23+, with back button interception.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

22/09/2019 - There's now a Kotlin version of this project.

system-alert-window-example

Example project showing use of SYSTEM_ALERT_WINDOW permission on Android 23+, with back button interception.

!!!IMPORTANT UPDATE!!! [2019-05-08] We all SAW it coming (pun intended), but the Android team have finally given us an idea of where the out-of-app UI interaction that system-alert-window enabled is going. Confirmed at Google IO 2019: it's going away. Part of the flakily-recorded "Whats New In Android" talk mentions it here.

  • On first launch, the app will check that it has permission to draw over other apps, and will show the user the corresponding prompt if not.
  • Once permission is granted, opening the app starts a service that inflates a layout and adds it to the screen as an overlay.

Note: This screenshot shows the example app drawing over the top of another running app: motorsport-circuits. So don't expect a map to appear when you run the example code! You just get the green box and bugdroid.

  • If any other app is running when the the app launches, they will lose focus, but onPause will not be called - the app behaves as a system alert, as the title suggests.

  • It's deliberately translucent and not full screen so that other apps can be seen running in the background, but you can make the app run full window by modifying the layout XML, and making the background colour opaque.

  • KeyEvent interception is shown on the back button; if you try to press the back button whilst the alert is shown, it'll be intecepted and a message shown in the logs.

  • Touches are intercepted whilst the alert/app is shown, even though other apps might be visible in the background they can't be interacted with.

  • Touch the View itself to close and kill the Service.

About

Example project showing use of SYSTEM_ALERT_WINDOW permission on Android 23+, with back button interception.


Languages

Language:Java 100.0%