2

I am building a new lock screen for Android, but I am unable to lock the notification bar from pulling it down.

I want to disable the notification bar pull-down.

InnocentKiller
  • 5,207
  • 7
  • 34
  • 84
user3442136
  • 21
  • 1
  • 1
  • 2

3 Answers3

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;
    }

}
NitinM
  • 293
  • 4
  • 11
  • This will also disable the notification panel from being pulled – NitinM Mar 22 '16 at 09:59
  • what is that customViewGroup? – beginner May 05 '16 at 10:08
  • @beginner : Thanks Man.. Forgot to add CustomViewGroup Class, edited the answer. – NitinM May 06 '16 at 12:55
  • 2
    For me, this crashes on lolipop with java.lang.RuntimeException: Unable to start activity ComponentInfo{tzgames.drivesafe/tzgames.drivesafe.BlockActivity}: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@8933a45 -- permission denied for this window type – travisjayday Aug 12 '17 at 17:50
  • This works. But after you finish the activity, the behaviour remains. How to enable the notification bar pull again before exiting? – Harish Vishwakarma Sep 08 '17 at 13:05
  • 1
    it doesnt in new Android versions... 6.0+ , I use android 9 – Jorgesys Jul 24 '19 at 18:01
1

Unless you modify system SystemUI.apk file, it's not possible, even then your app will require root permissions. The best you could do is create an app in fullscreen mode which will hide notification bar.

arleitiss
  • 107
  • 2
  • 13
0

Firstly, you need the EXPAND_STATUS_BAR permission:

<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />

and hope this link will help you for sure..

Community
  • 1
  • 1
Akshay
  • 5,721
  • 7
  • 39
  • 58
  • I have already done that one. In that we can click the notification in between the bar collapses. I need that there should be no access to the notification bar when the screen is locked. – user3442136 Mar 24 '14 at 08:06
  • Please see my answer above – NitinM Dec 15 '16 at 20:25