如何在“优先级应用程序通知"下查找允许使用哪些应用程序?在“请勿打扰"设置中? [英] How to find which apps are allowed under "Priority app notifications" within Do Not Disturb setting?

查看:67
本文介绍了如何在“优先级应用程序通知"下查找允许使用哪些应用程序?在“请勿打扰"设置中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式找出哪些应用程序的请勿打扰"设置被绕过了.

I am trying to programmatically find out for which apps the Do Not Disturb setting is bypassed exceptionally.

到目前为止,我正在使用以下代码检查手机是否设置为请勿打扰"模式:

So far, I am using the following code to check whether the phone is set in Do not Disturb mode or not :

public static boolean isDnDModeEnabled(Context context)
{
    if(Build.VERSION.SDK_INT <23)
        return false;

    try {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        int filterValue = notificationManager.getCurrentInterruptionFilter();
        switch(filterValue)
        {
            case NotificationManager.INTERRUPTION_FILTER_ALL : Log.d("DND","Interruption filter all");
                break;
            case NotificationManager.INTERRUPTION_FILTER_ALARMS : Log.d("DND","Interruption filter alarms");
                break;
            case NotificationManager.INTERRUPTION_FILTER_PRIORITY : Log.d("DND","Interruption filter priority");
                break;
            case NotificationManager.INTERRUPTION_FILTER_UNKNOWN : Log.d("DND","Interruption filter unknown");
                break;
            case NotificationManager.INTERRUPTION_FILTER_NONE : Log.d("DND","Interruption filter none");
                break;

        }
        if(filterValue == NotificationManager.INTERRUPTION_FILTER_ALL)
            return false;
        else if(filterValue == NotificationManager.INTERRUPTION_FILTER_PRIORITY)
        {
            //Logic based on which apps are allowed as priority

            return true; //or false
        }
        else
            return true;
    }
    catch(Exception e)
    {
        return false;
    }
}

当我点击优先应用程序通知标签时,我会获得所有已安装应用程序的列表,可以选择允许哪些应用程序作为优先级例外.

When I click on the Priority app notiications tab, I get a list of all installed apps for which I get to choose which apps to allow as priority exceptions.

我的问题是如何以编程方式 获取在请勿打扰"模式下被允许作为优先例外的应用程序列表,从而在上面的代码中定义替换注释的逻辑?任何解决方案将不胜感激.

My question is how to programmatically get the list of apps which are allowed as priority exceptions for Do Not Disturb mode, and thereby define the logic replacing the comment in the above code? Any solutions would be thoroughly appreciated.

推荐答案

您正在寻找一种确定系统上哪些应用的通知重要性为 Notification.IMPORTANCE_MAX 的方法,抱歉说,但这是非系统应用程序无法实现的.您需要访问 INotificationService ,以便可以调用 getImportance(packageName).请参见通知管理器源,但它是

You're looking for a way to determine which apps on the system have a notification importance of Notification.IMPORTANCE_MAX and, sorry to say but this is not possible by a non-system app. You need access to the INotificationService so you can call getImportance(packageName). See the Notification Manager source but it's guarded by a check that ensures you're a system app or the app whose package you passed so reflection is out...

Google允许应用通过 NotificationManager getImportance()(

Google allows an app to obtain its own notification importance through the NotificationManager with getImportance() (see docs) but you can't call it with an arbitrary package.

这里的另一个答案引用了从系统设置应用程序中检出源代码,这正是我所做的,并且在查找代码一段时间后,我发现它们是如何确定哪些应用程序应显示在"Overrides Do Not"中.通过此代码导致我发现如何确定 IMPORTANCE _ *

The other answer here references checking out the source from the system settings app and that's exactly what I did and, after a while of tracing through the code, I discovered how they determine which apps should show up in the "Overrides Do Not Disturb" menu by this code here which led me down the path of discovering how we could determine the IMPORTANCE_*

对不起,但是其他答复者提出的建议也将不起作用,因为它们要么不正确(packages.xml没有信息),要么将需要root权限,而该root权限在所有设备上都不可靠

Sorry man, but the suggestions made by the other answerer are also not going to work because they are either incorrect (packages.xml doesn't have the info) or are going to require root which isn't reliable on all devices.

这篇关于如何在“优先级应用程序通知"下查找允许使用哪些应用程序?在“请勿打扰"设置中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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