java - 在 Android P 和 Q Beta 中以编程方式切换异常时出现意外行为
问题描述
我有一个非常简单的应用程序,只有一个按钮。当我按下此按钮时,我希望以编程方式切换“仅来自已加星标的联系人”和“播放媒体声音”。我正在使用的代码是:
private void setPolicyStarredContacts() {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
assert notificationManager != null;
notificationManager.setNotificationPolicy(
new NotificationManager.Policy(PRIORITY_CATEGORY_MEDIA,
NotificationManager.Policy.PRIORITY_SENDERS_STARRED,
NotificationManager.Policy.PRIORITY_SENDERS_ANY));
}
实际发生的是只有“播放媒体声音”被激活,而不是其他选项。对于我做错了什么的一些迹象,我将不胜感激。干杯!
解决方案
Ok, I have actually found the answer! Here it is for future searchers:
private void setPolicyStarredContacts() {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
assert notificationManager != null;
notificationManager.setNotificationPolicy(
new NotificationManager.Policy(PRIORITY_CATEGORY_CALLS | PRIORITY_CATEGORY_MEDIA,
NotificationManager.Policy.PRIORITY_SENDERS_STARRED,
NotificationManager.Policy.PRIORITY_SENDERS_ANY));
}
推荐阅读
- verilog - 使用 xilinx vivado 2018.2 在 systemverilog 中随机化 32 位值
- git - 合并 git 分支。我的本地分支在许多已移动到 master 上的文件中有数百个小编辑
- c# - DocuSign JWT 身份验证:意外的 PEM 类型
- wordpress - 在本地主机上安装 WordPress
- kdb - KDB - 似乎无法将 csv 文件导入表
- javascript - 每次调用的多个 ajax 调用都会更新变量
- html - 应用 tbody 时的区别 td:nth-of-type(3){ border-bottom-color: transparent; } 和 tr.noborder td{ 边框底部:透明;} 在 CSS 中
- php - PDO lastInsertid() 返回 false,即使我的查询运行良好。给出 0000 代码错误
- ballerina - 如何在 Ballerina 中迭代字符串?
- javascript - 按属性值查找对象属性的索引