java - 如何实现 ZenPolicy 规则?
问题描述
这里有人知道 ZenPolicy 以及如何实施规则吗?我正在尝试复制不允许呼叫通过的“请勿打扰”设置,但可能存在例外情况,例如。媒体声音、触摸声音等。我已经设法禁止通话,但是当我(从我的应用程序)切换例外设置时,这将恢复为“仅限已加星标的联系人”。我附上了我试图在我的应用程序中复制的内容的屏幕截图。这是我到目前为止使用的代码:
3 -> {
notificationManager.setInterruptionFilter(
NotificationManager.INTERRUPTION_FILTER_PRIORITY
)
notificationManager.setNotificationPolicy(
NotificationManager.Policy(
PEOPLE_TYPE_NONE,
PRIORITY_SENDERS_ANY,
PRIORITY_SENDERS_ANY
)
)
}
我也看过:https ://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/service/notification/ZenModeConfig.java;drc=master;l= 754和https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/service/notification/ZenPolicy.java
并想出了这个功能,但它什么也没做......:
fun zenPolicyBuilder(): ZenPolicy.Builder {
val builder = ZenPolicy.Builder()
val calls = PRIORITY_CATEGORY_CALLS
val repeatCallers = PRIORITY_CATEGORY_REPEAT_CALLERS
val alarms = PRIORITY_CATEGORY_ALARMS
val media = PRIORITY_CATEGORY_MEDIA
val system = PRIORITY_CATEGORY_SYSTEM
val events = PRIORITY_CATEGORY_EVENTS
val reminders = PRIORITY_CATEGORY_REMINDERS
return when {
calls != ZenPolicy.PEOPLE_TYPE_UNSET -> {
builder.allowCalls(PEOPLE_TYPE_NONE)
}
repeatCallers != ZenPolicy.STATE_UNSET -> {
builder.allowRepeatCallers(repeatCallers == ZenPolicy.STATE_ALLOW)
}
alarms != ZenPolicy.STATE_UNSET -> {
builder.allowAlarms(alarms == ZenPolicy.STATE_ALLOW)
}
media != ZenPolicy.STATE_UNSET -> {
builder.allowMedia(media == ZenPolicy.STATE_ALLOW)
}
system != ZenPolicy.STATE_UNSET -> {
builder.allowSystem(system == ZenPolicy.STATE_ALLOW)
}
events != ZenPolicy.STATE_UNSET -> {
builder.allowEvents(events == ZenPolicy.STATE_ALLOW)
}
reminders != ZenPolicy.STATE_UNSET -> {
builder.allowReminders(reminders == ZenPolicy.STATE_ALLOW)
}
else -> builder
}
}
解决方案
For anyone who might be interested in future, the first code snippet that I posted actually works fine. The problem was coming from another part of my code which was interfering with this.
推荐阅读
- java - 改造 JSON 数组和对象现在工作类
- python - 使用条件在另一个 numpy 数组中组织数组
- javascript - 如何解决 MongoDB 中的最大大小问题?
- python - 正则表达式仅查找数字对然后连接值
- corda - Corda - 查询 QueryableState 子表
- javascript - 从 Gmail 创建日历活动?
- r - 无法在 R Plotly 中将所有小提琴设置为相同的宽度
- amazon-web-services - Istio 重置 AWS/ELB 配置中手动配置的更改
- next.js - NextJS SSR页面标题中的next-head-count是什么意思?
- blazor - 将组件插入现有的 dom 树