Granting SYSTEM_ALERT_WINDOW Permission on android 6.0 and above
From android 6.0 this permission needs to grant dynamically,
Throwing below permission denied error on 6.0,
Requesting Overlay permission as below,
Check for the result,
In order to put your view on top of every application, you have to assign your view to the corresponding window manager. For that you need the system alert permission, which can be requested by adding the following line to your manifest file:
Note: If your application gets destroyed, your view will be removed from the window manager. Therefore, it is better to create the view and assign it to the window manager by a foreground service.
Assigning a view to the WindowManager
You can retrieve a window manager instance as follows:
In order to define the position of your view, you have to create some layout parameters as follows:
Now, you can assign your view together with the created layout parameters to the window manager instance as follows:
Voila! Your view has been successfully placed on top of all other applications.
Note: You view will not be put on top of the keyguard.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0