我试图以编程的方式找出哪些应用程序被例外地绕过了“不干扰”设置。

到目前为止,我正在使用以下代码检查手机是否设置为“不干扰”模式:
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;
}
}当我单击“优先级应用程序通知”选项卡时,我会得到所有已安装应用程序的列表,其中我将选择允许哪些应用程序作为优先级例外。
我的问题是如何以编程的方式获得应用程序列表,这些应用程序被允许作为“不干扰”模式的优先级例外,从而定义了在上述代码中替换注释的逻辑?如有任何解决办法,将不胜感激。
发布于 2017-05-11 21:44:20
您正在寻找一种方法来确定系统上的哪些应用程序具有Notification.IMPORTANCE_MAX的通知重要性,很抱歉,这在非系统应用程序中是不可能的。您需要访问INotificationService以便调用getImportance(packageName)。请参阅通知管理器源,但由支票把守确保您是一个系统应用程序或应用程序,您传递的包,以使反射出.
谷歌允许应用程序通过NotificationManager with getImportance() (见文档 )获得自己的通知重要性,但你不能用任意的包来调用它。
这里的另一个答案是查看系统设置应用程序的源代码,这正是我所做的,经过一段时间的代码跟踪之后,我发现了它们是如何确定哪些应用程序应该显示在这里的代码的"Overrides“菜单中,这使我找到了如何确定IMPORTANCE_*的途径。
对不起,伙计,但是其他回答者提出的建议也不起作用,因为它们要么是不正确的(packages.xml没有信息),要么是需要在所有设备上都不可靠的根。
发布于 2017-05-11 20:40:45
您可以尝试以下一些事情(其中一些事情可能需要特权访问):
https://stackoverflow.com/questions/43766027
复制相似问题