1+ /*
2+ * MIUINativeNotifyIcon - Fix the native notification bar icon function abandoned by the MIUI development team.
3+ * Copyright (C) 2017-2023 Fankes Studio(qzmmcn@163.com)
4+ * https://github.com/fankes/MIUINativeNotifyIcon
5+ *
6+ * This software is non-free but opensource software: you can redistribute it
7+ * and/or modify it under the terms of the GNU Affero General Public License
8+ * as published by the Free Software Foundation; either
9+ * version 3 of the License, or any later version.
10+ * <p>
11+ *
12+ * This software is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+ * Affero General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU Affero General Public License
18+ * and eula along with this software. If not, see
19+ * <https://www.gnu.org/licenses/>
20+ *
21+ * This file is Created by fankes on 2023/4/17.
22+ */
23+ package com.fankes.miui.notify.utils.tool
24+
25+ import android.app.Notification
26+ import android.app.NotificationChannel
27+ import android.app.NotificationManager
28+ import android.app.PendingIntent
29+ import android.content.ComponentName
30+ import android.content.Context
31+ import android.content.Intent
32+ import android.graphics.drawable.Icon
33+ import android.os.Build
34+ import androidx.core.graphics.drawable.toBitmap
35+ import com.fankes.miui.notify.BuildConfig
36+ import com.fankes.miui.notify.R
37+ import com.fankes.miui.notify.utils.factory.appIconOf
38+
39+ /* *
40+ * 模块更新激活提醒通知工具类
41+ */
42+ object ActivationPromptTool {
43+
44+ /* * 当前模块的包名 */
45+ private const val MODULE_PACKAGE_NAME = BuildConfig .APPLICATION_ID
46+
47+ /* * 推送通知的渠道名称 */
48+ private const val NOTIFY_CHANNEL = " activationPromptId"
49+
50+ /* *
51+ * 推送提醒通知
52+ * @param context 当前实例
53+ * @param packageName 当前 APP 包名
54+ */
55+ fun prompt (context : Context , packageName : String ) {
56+ if (packageName != BuildConfig .APPLICATION_ID ) return
57+ context.getSystemService(NotificationManager ::class .java)?.apply {
58+ createNotificationChannel(
59+ NotificationChannel (
60+ NOTIFY_CHANNEL , " MIUI 原生通知图标 - 版本更新" ,
61+ NotificationManager .IMPORTANCE_DEFAULT
62+ ).apply { enableLights(false ) }
63+ )
64+ notify(packageName.hashCode(), Notification .Builder (context, NOTIFY_CHANNEL ).apply {
65+ setShowWhen(true )
66+ setContentTitle(" 模块已更新" )
67+ setContentText(" 点按通知打开模块以完成新版本激活。" )
68+ setColor(0xFFE06818 .toInt())
69+ setAutoCancel(true )
70+ setSmallIcon(Icon .createWithResource(MODULE_PACKAGE_NAME , R .drawable.ic_notify_update))
71+ setLargeIcon(context.appIconOf(packageName)?.toBitmap())
72+ setContentIntent(
73+ PendingIntent .getActivity(
74+ context, packageName.hashCode(),
75+ Intent ().apply {
76+ component = ComponentName (MODULE_PACKAGE_NAME , " ${MODULE_PACKAGE_NAME } .ui.activity.MainActivity" )
77+ flags = Intent .FLAG_ACTIVITY_NEW_TASK
78+ }, if (Build .VERSION .SDK_INT < 31 ) PendingIntent .FLAG_UPDATE_CURRENT else PendingIntent .FLAG_IMMUTABLE
79+ )
80+ )
81+ }.build())
82+ }
83+ }
84+ }
0 commit comments