我想在我的Android应用程序处于前台时隐藏其他应用程序的所有通知.这可能吗?如何? [英] I want to hide all notifications of other apps when my Android app is in foreground. Is this possible? How?

查看:289
本文介绍了我想在我的Android应用程序处于前台时隐藏其他应用程序的所有通知.这可能吗?如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个教育应用程序,学生可以在此进行5分钟的快速考试.他们大多数时候都在使用父母的手机.

I am creating an educational app where school students can appear for 5 mins quick exams. Most of the time they are using their parent's mobile phone.

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

Now what I want is that when a student is giving the exam, no notification should come from any other app such as WhatsApp, FB or Gmail.

这可能吗?如何?

推荐答案

一种可能的解决方案是将电话设置为DND(请勿打扰)模式.我尚未对此进行测试,但是根据文档,您应该可以这样做:

One possible solution would be to set the phone in DND (Do Not Disturb) mode. I haven't tested this but according to the documentation you should be able to do:

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:

This requires a special DND access permission though, and it requires Android M:

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

该权限需要由用户通过设置"接受.请参见此问题,以了解更多背景信息以及如何您可以启动导致该设置的活动.

That permission needs to be accepted by the user via Settings. See this question for more background and how you can launch the activity that leads to this setting.

第二种选择是使用屏幕固定在Android L中.

A second option is to use Screen Pinning, which was introduced in Android L.

这篇关于我想在我的Android应用程序处于前台时隐藏其他应用程序的所有通知.这可能吗?如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆