有没有办法暂时隐藏或禁用抬头通知?

Is there a way to hide or disable Heads-Up Notifications temporarily?

我到处搜索这个,我得到的最接近答案的是 this,它无法阻止单挑通知。

我正在创建一个自定义屏幕录制应用程序,当录制时我的应用程序中出现抬头通知时,这让我很烦。

有什么方法可以在屏幕录制时隐藏或禁用所有收到的通知?!

如果你能给我一个在非 root 设备上工作的例子,我将不胜感激。

看来您可以通过 NotificationManager 清除通知。

In API 23+ you can use both NotificationManager#setNotificationPolicy() and NotificationManager#setInterruptionFilter() (in that specific order) to control which notifications are shown to the user. Permissions are required for those APIs. Notice that this methods seem to be a convenience to be able to access the functionality, but skip implementing a complete NotificationListenerService. That's the only option that can work in a satisfying way

详情: