Android Creating Overlay always-on-top Windows edit

Popup overlay

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:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

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:

WindowManager mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);

In order to define the position of your view, you have to create some layout parameters as follows:

WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams(
mLayoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;

Now, you can assign your view together with the created layout parameters to the window manager instance as follows:

mWindowManager.addView(yourView, mLayoutParams);

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.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents
64 Menu
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
163 Creating Overlay always-on-top Windows
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close