TYPE_SYSTEM_OVERLAY in ICS

To create an overlay view, when setting up the LayoutParams DON’T set the type to TYPE_SYSTEM_OVERLAY. Instead set it to TYPE_PHONE. Use the following flags: FLAG_NOT_TOUCH_MODAL FLAG_WATCH_OUTSIDE_TOUCH FLAG_NOT_TOUCH_MODAL << I found this one to be quite important. Without it, focus is given to the overlay and soft-key (home, menu, etc.) presses are not passed to … Read more

Android activity over default lock screen

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); try using this flags to disable lock screen when the activity is started. After API level 17 you can use <activity android:name=”.yourActivityName” android:showOnLockScreen=”true” android:screenOrientation=”sensorPortrait” > showOnLockScreen like in the example…

Android: Unable to add window. Permission denied for this window type

if you use apiLevel >= 19, don’t use WindowManager.LayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT which gets the following error: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@40ec8528 — permission denied for this window type Use this instead: LayoutParams.TYPE_TOAST or TYPE_APPLICATION_PANEL

Android 1.6: “android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application”

Instead of : Context appContext = this.getApplicationContext(); you should use a pointer to the activity you’re in (probably this). I got bitten by this today too, the annoying part is the getApplicationContext() is verbatim from developer.android.com 🙁

What APIs are used to draw over other apps (like Facebook’s Chat Heads)?

This one: Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications. Very few applications should use this permission; these windows are intended for system-level interaction with the user. Constant Value: “android.permission.SYSTEM_ALERT_WINDOW” //EDIT: The full code here: public class ChatHeadService extends Service { private WindowManager windowManager; private ImageView … Read more