如何禁用Android中的通知栏下拉?

use*_*136 2 android lockscreen

我正在为Android构建一个新的锁定屏幕,但是我无法锁定通知栏以将其拉下来.

我想禁用通知栏下拉菜单.

Nit*_*inM 6

    private void disablePullNotificationTouch() {
            WindowManager manager = ((WindowManager) getApplicationContext()
                    .getSystemService(Context.WINDOW_SERVICE));
            WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
            localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
            localLayoutParams.gravity = Gravity.TOP;
            localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                    // this is to enable the notification to recieve touch events
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                    // Draws over status bar
                    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

            localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
            localLayoutParams.height = (int) (25 * getResources()
                    .getDisplayMetrics().scaledDensity);
            localLayoutParams.format = PixelFormat.RGBX_8888;
            customViewGroup view = new customViewGroup(this);
            manager.addView(view, localLayoutParams);
        }

//Add this class in your project
public 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) {

        Log.v("customViewGroup", "**********Intercepted");
        return true;
    }

}
Run Code Online (Sandbox Code Playgroud)

  • 对我来说,这会在lolipop上崩溃java.lang.RuntimeException:无法启动活动ComponentInfo {tzgames.drivesafe/tzgames.drivesafe.BlockActivity}:android.view.WindowManager $ BadTokenException:无法添加窗口android.view.ViewRootImpl $ W @ 8933a45 - 此窗口类型的权限被拒绝 (2认同)