Skip to content

Commit 729edfe

Browse files
author
Chenhe
committed
修复通知没有归属于对话分类
fix #16
1 parent 0f8c639 commit 729edfe

File tree

4 files changed

+79
-36
lines changed

4 files changed

+79
-36
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
88
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
99

10+
<queries>
11+
<package android:name="com.tencent.mobileqq" />
12+
<package android:name="com.tencent.minihd.qq" />
13+
<package android:name="com.tencent.qqlite" />
14+
<package android:name="com.tencent.tim" />
15+
</queries>
16+
1017
<application
1118
android:name="cc.chenhe.qqnotifyevo.MyApplication"
1219
android:allowBackup="true"
@@ -21,6 +28,7 @@
2128

2229
<service
2330
android:name="cc.chenhe.qqnotifyevo.service.NotificationMonitorService"
31+
android:exported="true"
2432
android:label="@string/service_notify"
2533
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
2634
<intent-filter>
@@ -30,6 +38,7 @@
3038
</service>
3139
<service
3240
android:name="cc.chenhe.qqnotifyevo.service.AccessibilityMonitorService"
41+
android:exported="true"
3342
android:label="@string/service_access"
3443
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
3544
<intent-filter>
@@ -46,6 +55,7 @@
4655
android:name=".service.NevoDecorator"
4756
android:description="@string/nevo_desc"
4857
android:directBootAware="true"
58+
android:exported="true"
4959
android:label="@string/nevo_name"
5060
android:permission="com.oasisfeng.nevo.permission.BIND_DECORATOR_SERVICE"
5161
tools:targetApi="N">
@@ -61,7 +71,9 @@
6171
android:value="cc.chenhe.qqnotifyevo.preference.PreferenceAty" />
6272
</service>
6373

64-
<receiver android:name="cc.chenhe.qqnotifyevo.StaticReceiver">
74+
<receiver
75+
android:name="cc.chenhe.qqnotifyevo.StaticReceiver"
76+
android:exported="true">
6577
<intent-filter>
6678
<action android:name="android.intent.action.BOOT_COMPLETED" />
6779
<action android:name="dnotShowNevoMultiMsgTips" />
@@ -71,6 +83,7 @@
7183
<activity
7284
android:name=".preference.PreferenceAty"
7385
android:excludeFromRecents="false"
86+
android:exported="true"
7487
android:label="@string/activity_splash"
7588
android:launchMode="singleInstance">
7689
<intent-filter>

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ package cc.chenhe.qqnotifyevo.core
33
import android.app.Notification
44
import android.app.PendingIntent
55
import android.content.Context
6+
import android.content.Intent
67
import android.graphics.Bitmap
78
import android.service.notification.StatusBarNotification
89
import androidx.annotation.VisibleForTesting
910
import androidx.core.app.NotificationCompat
1011
import androidx.core.app.Person
1112
import androidx.core.content.ContextCompat
13+
import androidx.core.content.pm.ShortcutInfoCompat
1214
import androidx.core.graphics.drawable.IconCompat
1315
import androidx.core.graphics.drawable.toBitmap
1416
import cc.chenhe.qqnotifyevo.R
17+
import cc.chenhe.qqnotifyevo.preference.PreferenceAty
1518
import cc.chenhe.qqnotifyevo.utils.*
1619
import timber.log.Timber
1720
import java.util.*
@@ -584,7 +587,8 @@ abstract class NotificationProcessor(context: Context) {
584587
largeIcon: Bitmap?,
585588
original: Notification,
586589
subtext: String? = null,
587-
title: String? = null, text: String? = null, ticker: String? = null
590+
title: String? = null, text: String? = null, ticker: String? = null,
591+
shortcutInfo: ShortcutInfoCompat? = null
588592
): Notification {
589593
val channelId = getChannelId(channel)
590594

@@ -613,6 +617,7 @@ abstract class NotificationProcessor(context: Context) {
613617
builder.setContentText(text)
614618
if (ticker != null)
615619
builder.setTicker(ticker)
620+
shortcutInfo?.also { builder.setShortcutInfo(it) }
616621

617622
setIcon(context, builder, tag, channel == NotifyChannel.QZONE)
618623

@@ -666,9 +671,24 @@ abstract class NotificationProcessor(context: Context) {
666671
val subtext =
667672
if (num > 1) context.getString(R.string.notify_subtext_message_num, num) else null
668673
Timber.tag(TAG).v("Create conversation notification for $num messages.")
674+
675+
val shortcut = ShortcutInfoCompat.Builder(context, conversation.name)
676+
.setIsConversation()
677+
.setPersons(conversation.messages.map { it.person }.toSet().toTypedArray())
678+
.setShortLabel(conversation.name)
679+
.setLongLabel(conversation.name)
680+
.setIcon(IconCompat.createWithBitmap(avatarManager.getAvatar(conversation.name.hashCode())))
681+
.setIntent(
682+
context.packageManager.getLaunchIntentForPackage(tag.pkg)
683+
?: Intent(context, PreferenceAty::class.java).apply {
684+
action = Intent.ACTION_MAIN
685+
}
686+
)
687+
.build()
669688
return createNotification(
670689
context, tag, channel, style,
671-
avatarManager.getAvatar(conversation.name.hashCode()), original, subtext
690+
avatarManager.getAvatar(conversation.name.hashCode()), original, subtext,
691+
shortcutInfo = shortcut
672692
)
673693
}
674694

app/src/main/java/cc/chenhe/qqnotifyevo/utils/Tag.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package cc.chenhe.qqnotifyevo.utils
33
/**
44
* 用于标记通知的来源。
55
*/
6-
enum class Tag {
7-
UNKNOWN,
8-
QQ,
9-
QQ_HD,
10-
QQ_LITE,
11-
TIM;
6+
enum class Tag(val pkg: String) {
7+
UNKNOWN(""),
8+
QQ("com.tencent.mobileqq"),
9+
QQ_HD("com.tencent.minihd.qq"),
10+
QQ_LITE("com.tencent.qqlite"),
11+
TIM("com.tencent.tim");
1212
}

app/src/main/java/cc/chenhe/qqnotifyevo/utils/Utils.kt

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,28 @@ const val GITHUB_URL = "https://github.com/liangchenhe55/QQ-Notify-Evolution/rel
4242
const val MANUAL_URL = "https://github.com/liangchenhe55/QQ-Notify-Evolution/wiki"
4343

4444
const val ALIPAY =
45-
"alipayqr://platformapi/startapp?saId=10000007&qrcode=https://qr.alipay.com/tsx12672qtk37hufsxfkub7"
45+
"alipayqr://platformapi/startapp?saId=10000007&qrcode=https://qr.alipay.com/tsx12672qtk37hufsxfkub7"
4646

4747
/**
4848
* 适配的应用包名列表。
4949
*/
5050
val packageNameList: List<String>
5151
get() = listOf(
52-
"com.tencent.mobileqq",
53-
"com.tencent.tim",
54-
"com.tencent.qqlite",
55-
"com.tencent.minihd.qq"
52+
Tag.QQ.pkg,
53+
Tag.TIM.pkg,
54+
Tag.QQ_LITE.pkg,
55+
Tag.QQ_HD.pkg,
5656
)
5757

5858
/**
5959
* 通知渠道 id 列表。
6060
*/
6161
val notificationChannelIdList: List<String>
6262
get() = listOf(
63-
NOTIFY_FRIEND_CHANNEL_ID,
64-
NOTIFY_FRIEND_SPECIAL_CHANNEL_ID,
65-
NOTIFY_GROUP_CHANNEL_ID,
66-
NOTIFY_QZONE_CHANNEL_ID
63+
NOTIFY_FRIEND_CHANNEL_ID,
64+
NOTIFY_FRIEND_SPECIAL_CHANNEL_ID,
65+
NOTIFY_GROUP_CHANNEL_ID,
66+
NOTIFY_QZONE_CHANNEL_ID
6767
)
6868

6969
fun getChannelId(channel: NotifyChannel): String = when (channel) {
@@ -80,40 +80,48 @@ fun getNotificationChannels(context: Context, nevo: Boolean): List<NotificationC
8080
val prefix = if (nevo) context.getString(R.string.notify_nevo_prefix) else ""
8181

8282
val att = AudioAttributes.Builder()
83-
.setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT)
84-
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
85-
.build()
86-
87-
val friendChannel = NotificationChannel(NOTIFY_FRIEND_CHANNEL_ID,
88-
prefix + context.getString(R.string.notify_friend_channel_name),
89-
NotificationManager.IMPORTANCE_HIGH).apply {
83+
.setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT)
84+
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
85+
.build()
86+
87+
val friendChannel = NotificationChannel(
88+
NOTIFY_FRIEND_CHANNEL_ID,
89+
prefix + context.getString(R.string.notify_friend_channel_name),
90+
NotificationManager.IMPORTANCE_HIGH
91+
).apply {
9092
description = context.getString(R.string.notify_friend_channel_des)
9193
setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), att)
9294
enableVibration(true)
9395
enableLights(true)
9496
}
9597

96-
val friendSpecialChannel = NotificationChannel(NOTIFY_FRIEND_SPECIAL_CHANNEL_ID,
97-
prefix + context.getString(R.string.notify_friend_special_channel_name),
98-
NotificationManager.IMPORTANCE_HIGH).apply {
98+
val friendSpecialChannel = NotificationChannel(
99+
NOTIFY_FRIEND_SPECIAL_CHANNEL_ID,
100+
prefix + context.getString(R.string.notify_friend_special_channel_name),
101+
NotificationManager.IMPORTANCE_HIGH
102+
).apply {
99103
description = context.getString(R.string.notify_friend_special_channel_des)
100104
setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), att)
101105
enableVibration(true)
102106
enableLights(true)
103107
}
104108

105-
val groupChannel = NotificationChannel(NOTIFY_GROUP_CHANNEL_ID,
106-
prefix + context.getString(R.string.notify_group_channel_name),
107-
NotificationManager.IMPORTANCE_HIGH).apply {
109+
val groupChannel = NotificationChannel(
110+
NOTIFY_GROUP_CHANNEL_ID,
111+
prefix + context.getString(R.string.notify_group_channel_name),
112+
NotificationManager.IMPORTANCE_HIGH
113+
).apply {
108114
description = context.getString(R.string.notify_group_channel_des)
109115
setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), att)
110116
enableVibration(true)
111117
enableLights(true)
112118
}
113119

114-
val qzoneChannel = NotificationChannel(NOTIFY_QZONE_CHANNEL_ID,
115-
prefix + context.getString(R.string.notify_qzone_channel_name),
116-
NotificationManager.IMPORTANCE_DEFAULT).apply {
120+
val qzoneChannel = NotificationChannel(
121+
NOTIFY_QZONE_CHANNEL_ID,
122+
prefix + context.getString(R.string.notify_qzone_channel_name),
123+
NotificationManager.IMPORTANCE_DEFAULT
124+
).apply {
117125
description = context.getString(R.string.notify_qzone_channel_des)
118126
setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), att)
119127
enableLights(true)
@@ -124,7 +132,8 @@ fun getNotificationChannels(context: Context, nevo: Boolean): List<NotificationC
124132

125133
private fun getCacheDir(context: Context): File {
126134
return if (Environment.MEDIA_MOUNTED == Environment.getExternalStorageState()
127-
|| !Environment.isExternalStorageRemovable()) {
135+
|| !Environment.isExternalStorageRemovable()
136+
) {
128137
context.externalCacheDir!!
129138
} else {
130139
context.cacheDir
@@ -133,7 +142,8 @@ private fun getCacheDir(context: Context): File {
133142

134143
private fun getDataDir(context: Context): File {
135144
return if (Environment.MEDIA_MOUNTED == Environment.getExternalStorageState()
136-
|| !Environment.isExternalStorageRemovable()) {
145+
|| !Environment.isExternalStorageRemovable()
146+
) {
137147
context.getExternalFilesDir(null)!!
138148
} else {
139149
context.filesDir

0 commit comments

Comments
 (0)