@@ -32,7 +32,7 @@ public class NotificationManagerUtils {
public static final String TAG = " NotificationManagerUtils " ;
// ********** 新增:通知版本管理常量 **********
/** 通知版本标识(源码标记版本,变更时会清理旧渠道) */
public static final String NOTIFICATION_VERSION = " v1.0.0 " ;
public static final String NOTIFICATION_VERSION = " v1.0.2 " ;
/** SP存储键: 已保存的通知版本 */
private static final String SP_KEY_NOTIFICATION_VERSION = " sp_key_notification_version " ;
/** SP文件名 */
@@ -156,10 +156,10 @@ public class NotificationManagerUtils {
* 初始化通知渠道:前台服务渠道(无铃声+无振动)、临时提醒渠道(系统默认铃声+无振动)
*/
private void initNotificationChannels ( ) {
LogUtils . d ( TAG , " initNotificationChannels() 方法调用 " ) ;
LogUtils . d ( TAG , " initNotificationChannels() 执行通知渠道初始化 " ) ;
// API<26 无渠道机制,直接返回
if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . O ) {
LogUtils . d ( TAG , " initNotificationChannels() API<26, 无需创建渠道,直接返回 " ) ;
LogUtils . d ( TAG , " initNotificationChannels() API<26, 无需创建渠道 " ) ;
return ;
}
// 通知服务为空,避免空指针
@@ -168,38 +168,38 @@ public class NotificationManagerUtils {
return ;
}
// 1. 前台服务渠道(低优先级,后台保活无打扰)
// 1. 拨号 前台服务渠道(低优先级,后台保活无打扰)
NotificationChannel foregroundChannel = new NotificationChannel (
CHANNEL_ID_FOREGROUND ,
" 拨号服务保活 " ,
" 拨号前台 服务 " ,
NotificationManager . IMPORTANCE_LOW
) ;
foregroundChannel . setDescription ( " 拨号服务后台运行,无声音、无振动 " ) ;
foregroundChannel . setDescription ( " 拨号前台 服务后台运行,无声音、无振动 " ) ;
foregroundChannel . enableLights ( false ) ;
foregroundChannel . enableVibration ( false ) ;
foregroundChannel . setSound ( null , null ) ;
foregroundChannel . setSound ( null , null ) ; // 强制无铃声
foregroundChannel . setShowBadge ( false ) ;
foregroundChannel . setLockscreenVisibility ( Notification . VISIBILITY_SECRET ) ;
LogUtils . d ( TAG , " initNotificationChannels() 前台服务渠道配置完成 " ) ;
LogUtils . d ( TAG , " initNotificationChannels() 拨号 前台服务渠道配置完成 " ) ;
// 2. 临时提醒 渠道(中优先级,系统默认铃声,无振动)
// 2. 其他临时通知 渠道(中优先级,系统默认铃声,无振动)
NotificationChannel temporaryChannel = new NotificationChannel (
CHANNEL_ID_TEMPORARY ,
" 临时通知提醒 " ,
" 临时通知 " ,
NotificationManager . IMPORTANCE_DEFAULT
) ;
temporaryChannel . setDescription ( " 拨号服务 临时通知,系统默认铃声,无振动" ) ;
temporaryChannel . setDescription ( " 其他 临时通知,系统默认铃声,无振动" ) ;
temporaryChannel . enableLights ( true ) ;
temporaryChannel . enableVibration ( false ) ;
temporaryChannel . setSound ( RingtoneManager . getDefaultUri ( RingtoneManager . TYPE_NOTIFICATION ) , Notification . AUDIO_ATTRIBUTES_DEFAULT ) ;
temporaryChannel . setShowBadge ( false ) ;
temporaryChannel . setLockscreenVisibility ( Notification . VISIBILITY_PUBLIC ) ;
LogUtils . d ( TAG , " initNotificationChannels() 临时提醒 渠道配置完成 " ) ;
LogUtils . d ( TAG , " initNotificationChannels() 其他临时通知 渠道配置完成 " ) ;
// 注册渠道到系统
mNotificationManager . createNotificationChannel ( foregroundChannel ) ;
mNotificationManager . createNotificationChannel ( temporaryChannel ) ;
LogUtils . d ( TAG , " initNotificationChannels() 成功:创建前台服务+临时提醒 渠道 " ) ;
LogUtils . d ( TAG , " initNotificationChannels() 成功:创建前台服务+其他临时通知 渠道 " ) ;
}
// ================================== 对外核心方法(前台服务通知:启动/更新/取消)=================================