【问题标题】:How to disable the notification bar pull-down in Android?如何在Android中禁用通知栏下拉?
【发布时间】:2014-03-20 13:07:15
【问题描述】:

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

我想禁用通知栏下拉。

【问题讨论】:

标签: android lockscreen


【解决方案1】:
    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;
    }

}

【讨论】:

  • 这也将禁止拉出通知面板
  • customViewGroup 是什么?
  • @beginner :谢谢伙计.. 忘记添加 CustomViewGroup 类,编辑了答案。
  • 对我来说,这在棒棒糖上崩溃并带有 java.lang.RuntimeException:无法启动活动 ComponentInfo{tzgames.drivesafe/tzgames.drivesafe.BlockActivity}:android.view.WindowManager$BadTokenException:无法添加window android.view.ViewRootImpl$W@8933a45 -- 此窗口类型的权限被拒绝
  • 它不在新的Android版本中...... 6.0+,我使用android 9
【解决方案2】:

除非您修改系统 SystemUI.apk 文件,否则这是不可能的,即使这样您的应用也需要 root 权限。 你能做的最好的就是在全屏模式下创建一个应用程序,它将隐藏通知栏。

【讨论】:

  • 请看我上面的回答
【解决方案3】:

首先,您需要 EXPAND_STATUS_BAR 权限:

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

希望这个link 对你有帮助..

【讨论】:

  • 我已经完成了那个。在那我们可以点击栏折叠之间的通知。我需要在屏幕锁定时不能访问通知栏。
  • 请看我上面的回答
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-04
  • 1970-01-01
  • 2013-02-15
  • 2020-01-01
  • 2011-12-08
相关资源
最近更新 更多