Skip to content

Commit 3af1432

Browse files
author
Chenhe
committed
修复传统模式下通知未归属于会话
fix #22
1 parent 64eb735 commit 3af1432

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

app/src/main/java/cc/chenhe/qqnotifyevo/core/InnerNotificationProcessor.kt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package cc.chenhe.qqnotifyevo.core
33
import android.app.Notification
44
import android.content.Context
55
import android.service.notification.StatusBarNotification
6+
import androidx.core.app.NotificationCompat
67
import androidx.core.app.NotificationManagerCompat
8+
import androidx.core.content.pm.ShortcutInfoCompat
9+
import androidx.core.content.pm.ShortcutManagerCompat
710
import cc.chenhe.qqnotifyevo.utils.NotifyChannel
811
import cc.chenhe.qqnotifyevo.utils.Tag
912
import timber.log.Timber
@@ -84,16 +87,28 @@ class InnerNotificationProcessor(
8487
// 确保只刷新新增的通知
8588
continue
8689
}
87-
notification = createConversationNotification(context, tag, channel, c, original).apply {
88-
contentIntent = original.contentIntent
89-
deleteIntent = original.deleteIntent
90-
}
90+
notification =
91+
createConversationNotification(context, tag, channel, c, original).apply {
92+
contentIntent = original.contentIntent
93+
deleteIntent = original.deleteIntent
94+
}
9195
sendNotification(context, tag, c.name.hashCode(), notification)
9296
commander.cancelNotification(sbn.key)
9397
}
9498
return notification ?: Notification() // 此处返回值没有实际意义
9599
}
96100

101+
override fun buildNotification(
102+
builder: NotificationCompat.Builder,
103+
shortcutInfo: ShortcutInfoCompat?
104+
): Notification {
105+
if (shortcutInfo != null) {
106+
ShortcutManagerCompat.pushDynamicShortcut(ctx, shortcutInfo)
107+
builder.setShortcutId(shortcutInfo.id)
108+
}
109+
return builder.build()
110+
}
111+
97112
private fun addNotifyId(tag: Tag, ids: Int) {
98113
when (tag) {
99114
Tag.QQ -> qqNotifyIds.add(ids)

app/src/main/java/cc/chenhe/qqnotifyevo/core/NotificationProcessor.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.core.app.NotificationCompat
1212
import androidx.core.app.Person
1313
import androidx.core.content.ContextCompat
1414
import androidx.core.content.pm.ShortcutInfoCompat
15+
import androidx.core.content.pm.ShortcutManagerCompat
1516
import androidx.core.graphics.drawable.IconCompat
1617
import androidx.core.graphics.drawable.toBitmap
1718
import cc.chenhe.qqnotifyevo.R
@@ -503,6 +504,14 @@ abstract class NotificationProcessor(context: Context) {
503504
// 清除 QQ 空间特别关心动态推送历史记录
504505
clearQzoneSpecialHistory(tag)
505506
}
507+
// 清除关联的 long live shortcut
508+
// 因为 QQ 的限制,shortcut 并不能直接跳转对话框,仅用于满足 Android 11 「会话」通知的要求
509+
// 所以保留它没有任何意义
510+
sbn.notification.shortcutId?.also { shortcutId ->
511+
if (shortcutId.isNotEmpty()) {
512+
ShortcutManagerCompat.removeLongLivedShortcuts(ctx, listOf(shortcutId))
513+
}
514+
}
506515
}
507516

508517
/**
@@ -617,15 +626,21 @@ abstract class NotificationProcessor(context: Context) {
617626
builder.setContentText(text)
618627
if (ticker != null)
619628
builder.setTicker(ticker)
620-
shortcutInfo?.also { builder.setShortcutInfo(it) }
621629

622630
setIcon(context, builder, tag, channel == NotifyChannel.QZONE)
623631

624-
return builder.build().apply {
632+
return buildNotification(builder, shortcutInfo).apply {
625633
extras.putString(NOTIFICATION_EXTRA_TAG, tag.name)
626634
}
627635
}
628636

637+
protected open fun buildNotification(
638+
builder: NotificationCompat.Builder,
639+
shortcutInfo: ShortcutInfoCompat?
640+
): Notification {
641+
return builder.build()
642+
}
643+
629644
protected fun createQZoneNotification(
630645
context: Context, tag: Tag, conversation: Conversation,
631646
original: Notification

0 commit comments

Comments
 (0)