mirror of
https://github.com/fankes/ColorOSNotifyIcon.git
synced 2025-09-04 09:45:34 +08:00
Added new module version update notification function
This commit is contained in:
@@ -52,6 +52,7 @@ import com.fankes.coloros.notify.param.IconPackParams
|
|||||||
import com.fankes.coloros.notify.param.factory.isAppNotifyHookAllOf
|
import com.fankes.coloros.notify.param.factory.isAppNotifyHookAllOf
|
||||||
import com.fankes.coloros.notify.param.factory.isAppNotifyHookOf
|
import com.fankes.coloros.notify.param.factory.isAppNotifyHookOf
|
||||||
import com.fankes.coloros.notify.utils.factory.*
|
import com.fankes.coloros.notify.utils.factory.*
|
||||||
|
import com.fankes.coloros.notify.utils.tool.ActivationPromptTool
|
||||||
import com.fankes.coloros.notify.utils.tool.BitmapCompatTool
|
import com.fankes.coloros.notify.utils.tool.BitmapCompatTool
|
||||||
import com.fankes.coloros.notify.utils.tool.IconAdaptationTool
|
import com.fankes.coloros.notify.utils.tool.IconAdaptationTool
|
||||||
import com.fankes.coloros.notify.utils.tool.SystemUITool
|
import com.fankes.coloros.notify.utils.tool.SystemUITool
|
||||||
@@ -556,11 +557,12 @@ object SystemUIHooker : YukiBaseHooker() {
|
|||||||
addAction(Intent.ACTION_PACKAGE_REPLACED)
|
addAction(Intent.ACTION_PACKAGE_REPLACED)
|
||||||
addAction(Intent.ACTION_PACKAGE_REMOVED)
|
addAction(Intent.ACTION_PACKAGE_REMOVED)
|
||||||
}) { context, intent ->
|
}) { context, intent ->
|
||||||
|
intent.data?.schemeSpecificPart?.also { packageName ->
|
||||||
|
if (intent.action.equals(Intent.ACTION_PACKAGE_REPLACED)) ActivationPromptTool.prompt(context, packageName)
|
||||||
if (intent.action.equals(Intent.ACTION_PACKAGE_REPLACED).not() &&
|
if (intent.action.equals(Intent.ACTION_PACKAGE_REPLACED).not() &&
|
||||||
intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)
|
intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)
|
||||||
) return@registerReceiver
|
) return@registerReceiver
|
||||||
if (ConfigData.isEnableNotifyIconFix && ConfigData.isEnableNotifyIconFixNotify)
|
if (ConfigData.isEnableNotifyIconFix && ConfigData.isEnableNotifyIconFixNotify)
|
||||||
intent.data?.schemeSpecificPart?.also { packageName ->
|
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
Intent.ACTION_PACKAGE_ADDED -> {
|
Intent.ACTION_PACKAGE_ADDED -> {
|
||||||
if (iconDatas.takeIf { e -> e.isNotEmpty() }
|
if (iconDatas.takeIf { e -> e.isNotEmpty() }
|
||||||
|
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* ColorOSNotifyIcon - Optimize notification icons for ColorOS and adapt to native notification icon specifications.
|
||||||
|
* Copyright (C) 2017-2023 Fankes Studio(qzmmcn@163.com)
|
||||||
|
* https://github.com/fankes/ColorOSNotifyIcon
|
||||||
|
*
|
||||||
|
* This software is non-free but opensource software: you can redistribute it
|
||||||
|
* and/or modify it under the terms of the GNU Affero General Public License
|
||||||
|
* as published by the Free Software Foundation; either
|
||||||
|
* version 3 of the License, or any later version.
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* and eula along with this software. If not, see
|
||||||
|
* <https://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2023/4/17.
|
||||||
|
*/
|
||||||
|
package com.fankes.coloros.notify.utils.tool
|
||||||
|
|
||||||
|
import android.app.Notification
|
||||||
|
import android.app.NotificationChannel
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.graphics.drawable.Icon
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
|
import com.fankes.coloros.notify.BuildConfig
|
||||||
|
import com.fankes.coloros.notify.R
|
||||||
|
import com.fankes.coloros.notify.utils.factory.appIconOf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模块更新激活提醒通知工具类
|
||||||
|
*/
|
||||||
|
object ActivationPromptTool {
|
||||||
|
|
||||||
|
/** 当前模块的包名 */
|
||||||
|
private const val MODULE_PACKAGE_NAME = BuildConfig.APPLICATION_ID
|
||||||
|
|
||||||
|
/** 推送通知的渠道名称 */
|
||||||
|
private const val NOTIFY_CHANNEL = "activationPromptId"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推送提醒通知
|
||||||
|
* @param context 当前实例
|
||||||
|
* @param packageName 当前 APP 包名
|
||||||
|
*/
|
||||||
|
fun prompt(context: Context, packageName: String) {
|
||||||
|
if (packageName != BuildConfig.APPLICATION_ID) return
|
||||||
|
context.getSystemService(NotificationManager::class.java)?.apply {
|
||||||
|
createNotificationChannel(
|
||||||
|
NotificationChannel(
|
||||||
|
NOTIFY_CHANNEL, "ColorOS 通知图标增强 - 版本更新",
|
||||||
|
NotificationManager.IMPORTANCE_DEFAULT
|
||||||
|
).apply { enableLights(false) }
|
||||||
|
)
|
||||||
|
notify(packageName.hashCode(), Notification.Builder(context, NOTIFY_CHANNEL).apply {
|
||||||
|
setShowWhen(true)
|
||||||
|
setContentTitle("模块已更新")
|
||||||
|
setContentText("点按通知打开模块以完成新版本激活。")
|
||||||
|
setColor(0xFF4E8A5A.toInt())
|
||||||
|
setAutoCancel(true)
|
||||||
|
setSmallIcon(Icon.createWithResource(MODULE_PACKAGE_NAME, R.drawable.ic_notify_update))
|
||||||
|
setLargeIcon(context.appIconOf(packageName)?.toBitmap())
|
||||||
|
setContentIntent(
|
||||||
|
PendingIntent.getActivity(
|
||||||
|
context, packageName.hashCode(),
|
||||||
|
Intent().apply {
|
||||||
|
component = ComponentName(MODULE_PACKAGE_NAME, "${MODULE_PACKAGE_NAME}.ui.activity.MainActivity")
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
}, if (Build.VERSION.SDK_INT < 31) PendingIntent.FLAG_UPDATE_CURRENT else PendingIntent.FLAG_IMMUTABLE
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}.build())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
app/src/main/res/drawable/ic_notify_update.xml
Normal file
9
app/src/main/res/drawable/ic_notify_update.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="50dp"
|
||||||
|
android:height="50dp"
|
||||||
|
android:viewportWidth="1024"
|
||||||
|
android:viewportHeight="1024">
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M906.4,791.6a247.9,247.9 0,0 0,-98.1 -186.5L808.3,399.4c0,-118.8 -85.1,-218.9 -197.4,-242.5v-4.7c0,-54.2 -44.5,-98.6 -98.8,-98.6 -54.3,0 -98.8,44.4 -98.8,98.6v4.7C300.8,180.5 215.7,280.4 215.7,399.4v205.8a247.7,247.7 0,0 0,-98.1 186.5h98.1v0.6h592.5v-0.6h98.1v-0.1zM491.1,970.4h24.5c64.3,0 117.8,-48.5 125.6,-110.7L383,859.8a126.8,126.8 0,0 0,125.6 110.7h-17.5z" />
|
||||||
|
</vector>
|
Reference in New Issue
Block a user