I am trying to implement an AlertWindow
kind of thing where I am using the instance of WindowsManager
to add a View
on it from a Service
. The View
is visible and accessible. But the back/home buttons on the on-screen NavigationBar
don't seem to respond. I am new to Android.
Here is a snippet of my code:
mLayout = new LinearLayout(this);
mLayout.setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT));
View view = LayoutInflater.from(this).inflate(R.layout.Mainactivity,
mLayout, true);
mTvErrorMsg = (TextView)view.findViewById(R.id.tv_error_msg);
mChkBoxAppState = (CheckBox)view.findViewById(R.id.chkbox_app_state);
mCancelBtn = (Button)view.findViewById(R.id.btn_action);
mEdtPin.addTextChangedListener(this);
try {
mWindowManager.addView(mLayout, wmlp);
} catch (RuntimeException e) {
SymLog.e(TAG, "Failed to add lock page.", e);
}
Adding the below LayoutParameters
solved my issue:
wmlp.flags = WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
wmlp.flags &= ~(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
wmlp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
wmlp.format = -1;
wmlp.token = null;
wmlp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;