为什么在小米设备中未激活“请勿打扰”?
Why Do Not Disturb is not activated in Xiaomi devices?
我正在使用此代码设置中断过滤器:
NotificationManager myNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
myNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY);
它在每台设备上都运行良好,但由于某些原因,它在使用 Android 9 的 小米 设备上运行不佳。不这些设备未激活打扰模式。它保持不变。如果我询问设备当前的中断是什么,它会回答值为 5。这是 Android 开发人员中未知且未记录的值,如 here.
所述
int iCurrentInterruption = oNotificationManager.getCurrentInterruptionFilter();
iCurrentInterruption 的值为 5。None 以下各项:
INTERRUPTION_FILTER_UNKNOWN = 0
INTERRUPTION_FILTER_ALL = 1
INTERRUPTION_FILTER_PRIORITY = 2
INTERRUPTION_FILTER_NONE = 3
INTERRUPTION_FILTER_ALARMS = 4
我猜在小米设备中,系统需要更长的时间来激活中断过滤器,所以你不能立即询问结果。
所以,我睡了一秒钟,然后再问。
有时它也不会在第一次被激活,所以我必须第二次调用 setInterruptionFilter。
像这样:
setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
wait
If INTERRUPTION_FILTER_PRIORITY==getCurrentInterruptionFilter() then return OK
//Second try:
setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
wait
If INTERRUPTION_FILTER_PRIORITY==getCurrentInterruptionFilter() then return Ok
return error
我正在使用此代码设置中断过滤器:
NotificationManager myNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
myNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY);
它在每台设备上都运行良好,但由于某些原因,它在使用 Android 9 的 小米 设备上运行不佳。不这些设备未激活打扰模式。它保持不变。如果我询问设备当前的中断是什么,它会回答值为 5。这是 Android 开发人员中未知且未记录的值,如 here.
所述int iCurrentInterruption = oNotificationManager.getCurrentInterruptionFilter();
iCurrentInterruption 的值为 5。None 以下各项:
INTERRUPTION_FILTER_UNKNOWN = 0
INTERRUPTION_FILTER_ALL = 1
INTERRUPTION_FILTER_PRIORITY = 2
INTERRUPTION_FILTER_NONE = 3
INTERRUPTION_FILTER_ALARMS = 4
我猜在小米设备中,系统需要更长的时间来激活中断过滤器,所以你不能立即询问结果。 所以,我睡了一秒钟,然后再问。 有时它也不会在第一次被激活,所以我必须第二次调用 setInterruptionFilter。
像这样:
setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
wait
If INTERRUPTION_FILTER_PRIORITY==getCurrentInterruptionFilter() then return OK
//Second try:
setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
wait
If INTERRUPTION_FILTER_PRIORITY==getCurrentInterruptionFilter() then return Ok
return error