gpt4 book ai didi

android - 当我的 Android 应用程序处于前台时,我想隐藏其他应用程序的所有通知。这可能吗?如何?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:41:45 24 4
gpt4 key购买 nike

我正在创建一个教育应用程序,学生可以在其中进行 5 分钟的快速考试。他们大部分时间都在使用 parent 的手机。

现在我想要的是,当学生参加考试时,任何其他应用程序(如 WhatsApp、FB 或 Gmail)都不应发出通知。

这可能吗?如何?

最佳答案

一种可能的解决方案是将手机设置为 DND(请勿打扰)模式。我没有对此进行测试,但根据您应该能够执行的文档:

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int currentFilter = notificationManager.getCurrentInterruptionFilter();
notificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_NONE);
// Run the exam...
// Restore the filter
notificationManager.setInterruptionFilter(currentFilter);

这需要特殊的 DND 访问权限,并且需要 Android M:

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

用户需要通过“设置”接受该权限。参见 this question了解更多背景信息以及如何启动导致此设置的 Activity 。

第二种选择是使用 Screen Pinning ,在 Android L 中引入。

关于android - 当我的 Android 应用程序处于前台时,我想隐藏其他应用程序的所有通知。这可能吗?如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51075189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com