@Override
public void onWindowFocusChanged(boolean hasFocus){
super.onWindowFocusChanged(hasFocus);
try{
if(!hasFocus && enableKioskMode){
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(closeDialog);
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
am.moveTaskToFront(getTaskId(), ActivityManager.MOVE_TASK_WITH_HOME);
// sametime required to close opened notification area
Timer timer = new Timer();
timer.schedule(new TimerTask(){
public void run() {
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(closeDialog);
}
}, 500);
}
}catch(Exception ex){
ex.printStackTrace();
}
}
private class CustomViewGroup extends ViewGroup {
public CustomViewGroup(Context context) {
super(context);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return true;
}
}
private void addBlockingViews() {
try {
WindowManager manager = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE));
//For Bottom View
WindowManager.LayoutParams bottomlocalLayoutParams = new WindowManager.LayoutParams();
bottomlocalLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
bottomlocalLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
bottomlocalLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
bottomlocalLayoutParams.height = (int) (50 * getResources().getDisplayMetrics().scaledDensity);
bottomlocalLayoutParams.format = PixelFormat.RGBX_8888;
bottomlocalLayoutParams.gravity = Gravity.BOTTOM;
bottomView = new CustomViewGroup(BaseActivity.this);
ViewGroup.LayoutParams layoutParams1 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 50);
bottomView.setLayoutParams(layoutParams1);
manager.addView(bottomView, bottomlocalLayoutParams);
WindowManager.LayoutParams toplocalLayoutParams = new WindowManager.LayoutParams();
toplocalLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
toplocalLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
int resId = getResources().getIdentifier("status_bar_height", "dimen", "android");
int result = 0;
if (resId > 0) {
result = getResources().getDimensionPixelSize(resId);
} else {
// Use Fallback size:
result = 60; // 60px Fallback
}
//toplocalLayoutParams.height = result;
toplocalLayoutParams.height = (int) (50 * getResources().getDisplayMetrics().scaledDensity);
toplocalLayoutParams.gravity = Gravity.TOP;
toplocalLayoutParams.format = PixelFormat.TRANSPARENT;
topView = new CustomViewGroup(BaseActivity.this);
ViewGroup.LayoutParams layoutParams2 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
25);
topView.setLayoutParams(layoutParams2);
manager.addView(topView, toplocalLayoutParams);
} catch (Exception e) {
e.printStackTrace();
}
}
My aim is to create a Kiosk app. I checked many codes for that like this and this. With their help I have achieved navigation bar hiding. Now I want to block user from dragging the notification bar down just like Surelock does. I've tried the common answers given in SO posts like here. But it does not work in my Redmi Note 5 Pro with Android Pie. Is there any other way to accomplish this?