I want to build a view on the top of every window.
I found this code:
bt = new Button(getApplicationContext());
LayoutParams param = new LayoutParams();
param.flags = LayoutParams.FLAG_NOT_FOCUSABLE;
param.format = PixelFormat.RGBA_8888;
param.type = LayoutParams.TYPE_SYSTEM_ALERT;
param.gravity = Gravity.TOP | Gravity.LEFT;
param.width = 40;
param.height = 40;
wmgr = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
wmgr.addView(bt, param);
and in manifest.xml
:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
The view is built but when I press the home button, I can't see anything except the status bar.
What's wrong? Please help me.
Change
wmgr = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
To
wmgr = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);